Activity生命周期

今天我就同过代码和大家一起了解一下Activity的生命周期.
这里是demo代码:

public class MainActivity extends Activity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e("MainActivity", "start onCreate");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.e("MainActivity", "start onStart");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.e("MainActivity", "start onPause");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e("MainActivity", "start onResume");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.e("MainActivity", "start onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e("MainActivity", "start onDestroy");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.e("MainActivity", "start onRestart");
    }

APP启动:onCreate->onStart->onResume
onCreate->onStart->onResume
点击home键:onPause->onStop
onPause->onStop
再次启动APP:onRestart->onStart->onResume
onRestart->onStart->onResume
点击返回键:onPause->onStop->onDestroy
onPause->onStop->onDestroy
点击任务键:onPause->onStop
onPause->onStop

如有错误或补充,请留言告知

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_15644753/article/details/79950226
文章标签: 生命周期 Activity
个人分类: java基础
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭