0
我想從第二個活動finish();
後面的第二個活動返回第一個活動的兩個字符串值。我嘗試使用下面的代碼,並沒有錯誤,我也無法獲得返回值。無法從之前的活動獲取數據
活動A
Intent intent = new Intent(activityA.this, activityB.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, 100);
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i(TAG, "onActivityResult");
if(resultCode == 100){
Bundle res = data.getExtras();
String contentid = res.getString("contentID");
String contenttype = res.getString("contentType");
Log.i(TAG, "contentid:" +contentid);
Log.i(TAG, "contenttype:" +contenttype);
}
}
活動B
@Override
public void onDestroy(){
super.onDestroy();
helper.close();
Intent intent = new Intent();
intent.putExtra("contentID", contentID);
intent.putExtra("contentType", contentType);
setResult(100, intent);
Log.i(TAG, "SETRESULT.................." +intent);
finish();
}
任何註釋或答案將不勝感激。
你得到'Log.i(標籤,「SETRESULT ..................」+意圖);'登錄logcat? – 2013-03-13 03:19:27
是...... SETRESULT .......................意向{(有額外)} – 2013-03-13 03:20:22