Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a method every time an activity is being viewed?

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!

like image 890
PeakGen Avatar asked Feb 15 '13 17:02

PeakGen


People also ask

What method is called on the activity when it is fully displayed?

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.

What method is called when the activity is called for the first time?

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.


1 Answers

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();
}
like image 61
A--C Avatar answered Sep 24 '22 20:09

A--C