Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Return to previous activity without calling finish()

Tags:

android

I have an android application with a LOT of activities, think of something like a book where every page is a new activity. The user can make changes in each activity, for example highlight certain texts with different colored markers etc. and it's crucial that I'll remember this information as long as the application stays alive (and I don't want/need to remember any of this when it's not). As I understand the best mechanism for storing this kind of information is via onSaveInstanceState(Bundle outState) and onCreate(Bundle)/onRestoreInstanceState(Bundle) rather than lets say, the Preferences mechanism. My only problem is that the user can navigate backwards to previous pages (Activities) and the only way i know of achieving this is by calling finish() which of course kills the current activity without calling onSaveInstanceState(Bundle outState) and even if it did call it, the next time I would launch an activity representing that page it would be an entirely new instance. So my question is: Is there a way to go back to the previous activity without calling finish()? or, is there a better way to save this information? maybe through static variables?

Thanks!

P.S. I know I could also implement my app differently so that not every page would have its own activity but this isn't the answer I'm looking for.

like image 419
Orr Matarasso Avatar asked Oct 26 '09 11:10

Orr Matarasso


1 Answers

Try to use startActivity() with flags such as Intent.FLAG_ACTIVITY_CLEAR_TOP. You could read the full story here: http://developer.android.com/reference/android/content/Intent.html#setFlags(int)

like image 97
Nguyen Minh Binh Avatar answered Oct 05 '22 23:10

Nguyen Minh Binh