Search code examples
androidlifecycleoncreateonresume

How can I know that OnResume comes after onCreate?


I have few activities and from one activity I open another and that go back to the first one...

The point is onCreate is called ones , and onResume every time when the activity is show. For example when I close B that was previouslly started from A, the onResume is called but not onCreate....

my problem is that I do not want to run the onResume if it comes after onCreate, I want to run the code only if onCreate wasn't called

Is this possible to do WITHOUT static flag ?

is there some method or flag from android like comesAfterOnCreate ?

@Override
protected void onResume() {
   if(comesAfterOnCreate){
       //DO not run this code
   }else{
      //run the long task
   }

I show a lot of answers with solution using static flag, Thanks to all of you for the effort and offering the help, but I was interested is there some method or something...


Solution

  • its not a difficult job, you can use boolean or see here Is that possible to check was onCreate called because of orientation change?