Issue
I have two differents methods that are executed on onCreate() and onResume(), but I want that when onCreate() is executed, the method in onResume don't run. Have some way to achieve this?
--EDIT--
I removed the piece of code from onCreate(), and created a flag to interact with onPause() and passed the boolean flag as params:
Boolean flagFirstTime = true;
@Override
public void onResume()
{
super.onResume();
new asyncTask().execute(flagFirstTime);
}
@Override
protected void onPause() {
super.onPause();
flagFirstTime = false;
}
Before I asked, I was thinking put a flag, but in my opinion, this is very ugly. XD
Solution
Create a module level boolean that is set in onCreate = true. When onResume executes, set it to false - after you pass by the method that should only run when the value is false. In this way, when the onResume is executed after an onPause, the methond in onResume will run.
boolean skipMethod = false;
onCreate(){
skipMethod = true;
}
onResume(){
if(!skipMethod){
myMethoed();
}
skipMethod = false;
}
Answered By - Roy Hinkley
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.