Android开发中,从A页面跳转到B页面的详细生命周期,最好有图文解释,
https://blog.csdn.net/u013728021/article/details/103562882
https://blog.csdn.net/ahui_123456789/article/details/126134658
A:onPause ->onSaveInstanceState-> B:onCreate -> B:onStart -> B:onResume -> A:onStop
答案:
当在安卓应用中从页面A跳转到页面B时,会涉及到以下生命周期函数的调用:
如果在B界面按返回键:
具体解决方案如下:
在A页面中实现跳转到B页面的逻辑,可以使用Intent进行页面跳转,如下所示:
Intent intent = new Intent(A.this, B.class);
startActivity(intent);
在B页面的onCreate()生命周期函数中,可以使用setContentView()方法初始化布局:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
}
调用startActivity()方法后,会调用B页面的onCreate()、onStart()和onResume()生命周期函数,此时B页面就显示在前台。
在B页面按返回键后,会调用B页面的onPause()、A页面的onRestart()、onStart()和onResume()生命周期函数,此时A页面显示在前台。
需要注意的是,在A页面被回收后,如果再返回A页面,会调用onCreate()、onStart()和onResume()生命周期函数。