我有兩個需要在它們之間傳遞對象數組的活動。從主要活動中,我從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