Android - disable the onResume () function if the activity is loaded the first time (without using SharedPreferences)

In my current application, the onResume function runs when I load Activity the first time. I looked at the activity life cycle , but I did not find a way to prevent this.

Can I prevent the onResume () function from loading the first time I load an Activity without using SharedPreferences?

+5
source share
1 answer

Firstly, as RvdK says, you should not change the life cycle of Android activity, you will probably have to redesign your behavior in order to be compatible with it.

, , :

1.

public class MyActivity extends Activity{
  boolean shouldExecuteOnResume;
  // The rest of the code from here..
}

2. onCreate:

public void onCreate(){
  shouldExecuteOnResume = false
}

3. onResume:

public void onResume(){
  if(shouldExecuteOnResume){
    // Your onResume Code Here
  } else{
     shouldExecuteOnResume = true;
  }

}

, onResume (shouldExecuteOnResume is false), , ( shouldExecuteOnResume true). ( ), , , onCreate , onResume ..

+18

All Articles