开发者

How can I pass data from the current Activity to a paused Activity?

开发者 https://www.devze.com 2022-12-14 16:16 出处:网络
I want to know how to pass data from the current 开发者_Python百科Activity to a paused Activity.

I want to know how to pass data from the current 开发者_Python百科Activity to a paused Activity.

Please advise.


Let's call the paused Activity "A" and the "current" Activity "B".

The way to have B communicate results to A is for A to call startActivityForResult() instead of startActivity(), and for B to use setResult() to provide the return value(s). A then receives those return values in onActivityResult().


in your current activity, create an intent

Intent i = new Intent(getApplicationContext(), PausedActivity.class);
i.putExtra(key, value);
startActivity(i);

then in paused activity, retrieve those values.

Bundle extras = getIntent().getExtras(); 
if(extras !=null) {
    String value = extras.getString(key);
}

if the data is complex, try http://developer.android.com/guide/appendix/faq/framework.html#3

0

精彩评论

暂无评论...
验证码 换一张
取 消