What methods are invoked in the Activity Lifecycle in the following cases:

前端 未结 4 1231
夕颜
夕颜 2020-12-13 11:15

Let\'s say I have a Hello World single Activity application. I start this application.

What methods are invoked in each case:

  • Home button is pressed:
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 11:29

    Well see, while a sequence of events may occur with your hello world program, the same sequence may not occur in say a video game, because Android will probably Destroy it for taking up too much resources.

    The best way I have found to see the lifecycle for my app is to override all the methods (onStart, onRestart,..., including the onSaveInstance and onRestoreInstance) and insert log statements in each one. Like so:

    @Override
    public void onDestroy() {
        // Call the super class 
        super.onDestroy();
        // Log the action
        Log.d("Debug", "onDestroy() has been called!");
    }
    

    Now I can go to logcat and see what events took place.

提交回复
热议问题