我有两个需要在它们之间传递对象数组的活动。从主要活动中,我从startActivityForResult()
开始次要活动,并将数组作为ParcelableArray传递给Bundle。这很好地使数组进入次要活动;我可以将数组拉出Bundle并从那里操作。Android活动结果
我遇到的问题是当我想将数组传回给调用活动时。我需要它在用户按下设备上的后退/返回按钮时发生。我已经尝试将数组放回到一个Bundle中,在次要活动中从onPause()
中调用setResult()
,但我假设这是执行任务的不正确位置。我已经得出结论getCallingActivity()
在onPause()
内返回null。
在这种情况下返回一个Bundle到调用活动的正确方法是什么?
主要活动:
Bundle b = new Bundle();
b.putParcelableArray("com.whatever.data", items);
Intent folderView = new Intent(MainView.this, FolderView.class);
folderView.putExtras(b);
startActivityForResult(folderView, 1);
次要活动:
protected void onPause() {
super.onPause();
Intent result = new Intent();
Bundle b = new Bundle();
b.putParcelableArray("com.whatever.data", items);
result.putExtras(b);
setResult(Activity.RESULT_OK, result);
}
做在'onkeydown事件的处理()'的伎俩。谢谢! – harrywynn 2009-11-26 02:03:12