我想从onCreate
方法调用onPause
方法。这可能吗?
答案 0 :(得分:1)
没有。您永远不应该对onCreate
(或任何其他Activity
生命周期方法)进行任何显式调用。系统为您管理Activity
生命周期,显式调用这些方法只会干扰。
答案 1 :(得分:0)
我在几个应用程序中有类似的需求。创建一个单独的(可能希望它是一个私有的)方法来完成所有脏工作并从两个地方调用。例如
@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
...
}