用户可以从活动返回的两种方式之一:
1)操作栏上的"home/up“按钮
2)从堆栈中弹出活动的后退按钮
我想在返回时传递一个数组列表,我为操作栏上的"home/up“按钮设置了如下内容:
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.home:
Intent retIntent = new Intent(getApplicationContext(),SecondaryActivity.class);
retIntent.putExtra(MainActivity.GEN_MESSAGE,returnVal);
startActivity(retIntent);
return true;
}
}但是,当活动从堆栈中弹出时,此逻辑不会命中。当act弹出时,我可以在哪里处理发生的事情?
谢谢大家
发布于 2015-10-14 12:00:34
你错过了setResult(RESULT_OK,retIntent);这行
在你的第二个练习中:
Bundle b = new Bundle();
b.putParcelableArrayList("key", arrayName);
Intent retIntent = new Intent(getApplicationContext(),SecondaryActivity.class);
retIntent.putExtra(MainActivity.GEN_MESSAGE,returnVal);
i.putExtras(b);
setResult(RESULT_OK,retIntent);
startActivity(retIntent);在第一个活动onActivityResult中
Bundle extras = intent.getExtras();使用extras.getString("key"):获取您的阵列
https://stackoverflow.com/questions/33115941
复制相似问题