I have two activities and one fragment in my app. The first activity, MainActivity
, is used to hold the fragment. It contains an ActionBarSherlock
ActionBar
and the fragment, WFrag
. WFrag
opens up the second activity, SettingsActivity
, when you press a button. In SettingsActivity
, you can choose settings that affect the behavior of WFrag
. Naturally, I want the onBackPressed()
method to go back to WFrag
and update it with the user's new settings. My question is: how do you make it so that when you go back (via the back button) from SettingsActivity
, you recreate (call onCreate()
again) WFrag
?
Asked
Active
Viewed 1,839 times
1

Aneesh Ashutosh
- 762
- 7
- 18
-
1override onBackPressed or add the update in onStart/onResume – Gina Aug 15 '13 at 03:00
-
That did it, thank you! Any way to mark a comment as the best answer? – Aneesh Ashutosh Aug 15 '13 at 12:00
-
Try the answer of GoodLife on the given link https://stackoverflow.com/questions/20340303/in-fragment-on-back-button-pressed-activity-is-blank/20340492 – meyasir Jun 20 '18 at 06:03
2 Answers
1
First you have to override onBackPressed() of SettingActivity.
Second when you start second activity i.e SettingActivity from MainActivity you have to clear Stack of previous activity in this way
Intent intent = new Intent(this, SettingActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Same goes for SettingActivity in onBackPressed() method you have to run your MainActivity in this way
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Or if you are redirecting to MainActivity from button click you can use above code for same.

Praveen
- 388
- 3
- 7