How to call a method every time an activity is being viewed?
For an example, I navigate from activity1
to activity2
. Now I again navigate to activity1
. Each and every time the activity1
is being displayed/navigated to that activity, I need to run the method loadEveryTime()
. How can I do this? Please help!
onStart() When the activity enters the Started state, the system invokes this callback. The onStart() call makes the activity visible to the user, as the app prepares for the activity to enter the foreground and become interactive. For example, this method is where the app initializes the code that maintains the UI.
in short onCreate is called first and when you comeback from an activity onResume will be called. onResume will also be called the first time as well.
onResume()
is called every time the Activity is resumed, so put your method call in there. Make sure to call up to the superclass.
@Override
protected void onResume()
{
super.onResume();
loadEveryTime();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With