Override onPause()
method in Activity
with an image (to understand why onPause
, check life cycle of an Activity diagram here: http://developer.android.com/reference/android/app/Activity.html) like this:
@Override
protected void onPause() {
SharedPrefrences sp = getSharedPreferences("AppSharedPref", 0); // Open SharedPreferences with name AppSharedPref
Editor editor = sp.edit();
editor.putString("ImagePath", selectedImagePath); // Store selectedImagePath with key "ImagePath". This key will be then used to retrieve data.
editor.commit();
super.onPause();
}
It means that whenever this Activity
goes into background, the image path will be saved in SharedPreferences
with name AppSharedPref
- this name can be whatever you like, but you need to use the same one when retrieving data.
Then override onResume()
method in the same Activity
so that you can retrieve image path when Activity
comes to foreground:
@Override
protected void onResume() {
SharedPreferences sp = getSharedPreferences("AppSharedPref", 0);
selectedImagePath = settings.getString("ImagePath", "");
super.onResume();
}
You may also want to play with overriding other methods, like for example onStart()
according to diagram, but this I leave to you.