Issue
Is there a way to send updated data to a parent activity when back is pressed? I'd like to update the data in the bundle, but I don't see how I would access it.
For example, I have a gallery activity that opens an image viewer. Say a user scrolls through a dozen images and then backs out to the gallery. It would be ideal to update the focal image in the gallery with the last image they viewed.
At the moment I can't think of how to do so without a global setting.
Here's pseudo code of what I'd like to do (although this obviously wouldn't work):
Child:
@Override
public void onBackPressed() {
getIntent().setData(currentImage); // Not the right intent, obviously
super.onBackPressed();
}
Parent:
@Override
public void onResume()
{
super.onResume();
Uri photoFocus = getIntent().getData();
if (photoFocus != null)
setPhotoFocus(photoFocus);
}
Solution
you can do
startActivityForResult()
from your parent activity when you start childactivity. onBackPressed, you can call setResult() in your childActivity.
In parentActivity the code will come to callback :
protected void onActivityResult(int requestCode, int resultCode, Intent data) { }
where you can extract the result set in setResult method
OR
use sharedPreferences
Answered By - Sushil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.