0

I have a dashboard Activity and a user Activity. On every operation in dashboard I will start user Activity using startActivity(). If the user pressed back button in user Activity I want to show dashboard Activity again. Please give guidelines to implement this which should also handle when the dashboard Activity is killed due to low memory.

jszumski
  • 7,430
  • 11
  • 40
  • 53
vignesh
  • 1,573
  • 7
  • 33
  • 60
  • Check if the `Dashboard Activity` is still in the `Activity Stack` using this answer: http://stackoverflow.com/a/6242122/450534. If it is not, fire an Intent to launch the `Dashboard Activity` again and call `finish()` on the current `Activity`. In theory, I think this will work. Since I haven't tested it, it goes as a comment. ;-) – Siddharth Lele Apr 26 '13 at 04:07
  • in onPause() you can use check if(isFinishing()) in your activitys to execute code while activity is finishing too – JRowan Apr 26 '13 at 04:09

1 Answers1

0

The Android framework will take care of that for you. When you call startActivity() it pushes the new activity on top of the current task's stack (unless you tweak the launch mode or set intent flags)

When the user presses back, it pops the current activity off the stack and returns to the previous activity.

If the framework killed any of the previous activities, they are recreated. If you had any instance data in those activities that you still need, you should override onSaveInstanceState() to store it and onRestoreInstanceState() to recover it (data in system Views that have ids assigned are automatically saved/restored).

Please see Tasks and the Back Stack for details.

The only potentially tricky part is if you jump into the application on the user page via intent, but still want back to go to the dashboard, you will need to be sure to prepare the back stack via a TaskStackBuilder.

Scott Stanchfield
  • 29,742
  • 9
  • 47
  • 65