tags:

views:

321

answers:

3

hi guys.

I wanna know how to pass data from current Activity to paused Activity ?

Please advice. Thanks in advance.

+2  A: 

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

yanokwa
thanks for response.I think this code will be used for creating new intent of PausedActivity. I use it when finish current Activity and create new activity.It is not passing data to Paused Activity.My code is little different : Intent intent = new Intent(); intent.setClass(CurrentActivity.this, NewActivity.class); intent.putExtra("key", "value"); startActivity(intent); this.finish();I wanna pass a value direcly from current activity to Paused Activity (previous activity) without new intent.Thanks.
AndroiDBeginner
i believe commonsware.com's answer is the best way to solve this problem. your alternative is to store the results in a database and when the paused activity is resumed, you retrieve those results.
yanokwa
A: 

thanks for response.

I think this code will be used for creating new intent of PausedActivity. I use it when finish current Activity and create new activity.

It is not passing data to Paused Activity.

My code is little different :

        Intent intent = new Intent();
 intent.setClass(CurrentActivity.this, NewActivity.class);
 intent.putExtra("key", "value");
 startActivity(intent);
 this.finish();

I wanna pass a value direcly from current activity to Paused Activity (previous activity) without new intent.

Thanks.

AndroiDBeginner
+2  A: 

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().

CommonsWare