Search code examples
androidonresume

How to identify which Activity was 'opened' in onResume


In my main activity I want to override the onResume method so it acts differently, depending on the activity, which was opened before. For example: if the user creates a new Item for the listView (in the addNewItem activity), I need to reload the database to display the newItem. But if he just switches into an activity, which doesn't change anything with the objects displayed in the main activity, the database shouldn't be reloaded and the GUI shouldn't be build again. Therefor I need to know which activity was 'opened' before.

I hope you understand my problem.


Solution

  • A dirty way is to extend your application class and set an attribute lastActivity that you would set in every onResume/OnPause methods of every activities in your app. This way, when your main activity on resume is called, just read this lastActivity field to know where you come from. But I think it's the dirty way to do it :D