如何将二维数组传递给广播接收器类

时间:2014-04-24 11:17:13

标签: android arrays android-intent broadcastreceiver

我是Android的新手,面临传递意图的问题,我的主要活动类将意图传递给实现广播接收器的类,而意图包含二维数组

//这里curDts是我的二维数组

Bundle b=new Bundle();
        b.putSerializable("dates", curDts );
        Intent intent = new Intent(this, AlarmReceiver.class);
        intent.putExtras(b);

public void onReceive(Context arg0, Intent arg1) {
    Bundle b = arg1.getExtras();
    //Log.v("hahahha","curDts");
        String[][] my_date = (String[][])b.getSerializable("dates");
        Log.v("dates",my_date+"--");
    }

此处my_date显示为空

1 个答案:

答案 0 :(得分:0)

像这样。但我从来没有编译和运行它。

Bundle b=new Bundle();   
Intent intent = new Intent(this, AlarmReceiver.class);         
intent.putExtra("len", curDts.length);
    for(int i = 0; i < curDts.length; i++){
       intent.putExtra("item" + i, curDts[i]);
    }

public void onReceive(Context arg0, Intent arg1) {
//Log.v("hahahha","curDts");
    String[][] my_date = new String[][arg1.getIntExtra("len")];
    for(int i = 0; i < arg1.getIntExtra("len"); i++){
         my_date[i] = arg1.getStringArrayExtra("item"+i, null);
    }
    Log.v("dates",my_date+"--");
}