Won*_*abo 15 android android-intent android-activity
我开始一个新的Activity
从原来的Activity
使用startActivityForResult(intent, requestCode)
.我想Activity
在用户按下后退按钮时将数据返回到原始数据,因此返回原始数据时Activity
.我尝试了两种方法:
压倒一切onBackPressed()
:
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent();
intent.putIntegerArrayListExtra(SELECTION_LIST, selected);
setResult(RESULT_OK, intent);
}
Run Code Online (Sandbox Code Playgroud)压倒一切onPause()
:
@Override
protected void onPause() {
super.onPause();
Intent intent = new Intent();
intent.putIntegerArrayListExtra(SELECTION_LIST, selected);
setResult(RESULT_OK, intent);
}
Run Code Online (Sandbox Code Playgroud)不幸的是,他们没有工作(resultCode
不RESULT_OK
中onActivityResult()
).这样做的正确方法是什么?谢谢!
Pra*_*rma 23
试试这个 :
@Override
public void onBackPressed() {
// super.onBackPressed();
Intent intent = new Intent();
intent.putIntegerArrayListExtra(SELECTION_LIST, selected);
setResult(RESULT_OK, intent);
finish();
}
Run Code Online (Sandbox Code Playgroud)
由于这个问题仍然受到关注,我发布的答案比我两年前接受的答案更正确,感谢MasterGaurav的提示.
@Override
public void onBackPressed() {
Intent intent = new Intent();
intent.putIntegerArrayListExtra(SELECTION_LIST, selected);
setResult(RESULT_OK, intent);
super.onBackPressed();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
28295 次 |
最近记录: |