我正在尝试从活动2中获取编辑后的列表并返回到活动1。这是我的代码:
public void listDataSms(ArrayList<MySmsLog> stringList) {
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(NUMBER_LIST, stringList);
Intent i = new Intent(this, MyCommonListActivity.class);
i.putExtra(WHO_INT, SMS_LOG);
i.putExtras(bundle);
startActivityForResult(i, SMS_LOG);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SMS_LOG) {
if (resultCode == RESULT_OK) {
ArrayList<MySmsLog> mySmsLogs = (data.getParcelableArrayListExtra(PICK_SMS_LOG));
mainLog.setSmsLog(mySmsLogs);
}
if (resultCode == RESULT_CANCELED) {
// do something if there is no result
}
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent();
Bundle result = new Bundle();
switch (who) {
case SMS_LOG:
result.putParcelableArrayList(MainActivity.PICK_SMS_LOG, mySmsLogList);
break;
}
setResult(RESULT_OK, intent);
intent.putExtras(result);
}
但是我从来没有得到 setSmsLog
,因为 resultCode
总是 0
。
我尝试了Android onActivityResult 总是 0,但没有结果。
即使我把条件改成 if (resultCode == RESULT_CANCELED) {do smth}
,程序也会以 NullPointerException
结束。
MyCommonListActivity
活动是如何终止的? - Aniket Thakur