user1371595
user1371595

Reputation: 21

Calling override activity and not following activity life cycle

I want to call the onCreate method from the onPause method. Is this possible?

Upvotes: 1

Views: 179

Answers (2)

MikeIsrael
MikeIsrael

Reputation: 2889

I have had a similar demand in several applications. Create a separate (probably want it to be a private) method for doing all the dirty work and call from both places. For example

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    //call your init function here
    init();
    ...
}
@Override
public void onPause() {
    super.onPause(); 
    //call your init function here
    init();
}

//your init stuff
private void init(){
    //do all of the stuff you need to do in onCreate and onPause here
    ...
}

Upvotes: 0

Alex Lockwood
Alex Lockwood

Reputation: 83311

No. You should never make any explicit calls to onCreate (or any other Activity lifecycle method for that matter). The system manages the Activity lifecycle for you, and explicitly calling these methods will only interfere.

Upvotes: 1

Related Questions