2

I have a method that gets called both from onNavigationItemSelected of ActionBar and onResume lifecycle methods. So, when the Activity gets created, the method gets called twice.

So will it be possible to implement like that when the method is called from onNavigationItemSelected, it should not get called from onResume?

jaibatrik
  • 6,770
  • 9
  • 33
  • 62

3 Answers3

1

Only call your method in onResume. onResume is called when the Activity is created the first time as well. See Activity Lifecycle for further details.

florian h
  • 1,162
  • 1
  • 10
  • 24
1

Use a manual flag/boolean as used here android action bar onNavigationItemSelected

so that you can ignore the first call to onNavigationItemSelected method

Community
  • 1
  • 1
baboo
  • 1,983
  • 17
  • 23
0

In Activity life cycle OnCreate() is called only once and OnResume() is called every time after stop, pause, start and before OnCreate. So decide what you actually want. If you want to call method on every resume then call it only in OnResume not in OnCreate..