0

I would like to save state of an activity when you navigate away from it. For example, you have Activity A with filled in text on it and you navigate to Activity B using an intent. Well when you go back to Activity A using an Intent you lose all the text you had on that screen.

When I use the soft key back button on most android phones, the screens text stays on there, I would like to mimic that method of keeping the text on screen between navigation.

The last thing I want to do is pass parameters between all my screens, there are a lot of forms and the users dont have to follow a specific nav order.

Evgeniy Mishustin
  • 3,343
  • 3
  • 42
  • 81
ebolton
  • 1,126
  • 3
  • 14
  • 20
  • you could create a singleton to represent the data on the screen you want to save, then reference the singleton when the screen is reloaded – GregH Dec 29 '15 at 16:35
  • I'll have a look at how those work, ty – ebolton Dec 29 '15 at 16:36
  • 1
    here is a good post which outlines a few different methods of achieving your first goal (including the singleton method which I suggested): http://stackoverflow.com/questions/4878159/whats-the-best-way-to-share-data-between-activities – GregH Dec 29 '15 at 16:38
  • 1
    You should save activity data in onPause() method, it's the most safe method to save data when activity or fragment is supposed to go off the screen. Singleton might raise any issue if you're opening same activity from multiple activities and you're passing different data everytime, you'll have to nullify those data explicitly. – Apurva Dec 29 '15 at 16:39

0 Answers0