相关疑难解决方法(0)

在onPause,onStop和onDestroy方法中调用超类方法的正确顺序是什么?为什么?

我刚刚浏览了Android Developer Site,刷新了Activity Life周期,在每个代码示例中,超类方法旁边都有一条注释,"首先调用超类方法".

虽然这在创建半周期中有意义:onCreate,onStart和onResume,但我对于破坏半周期的正确程序有点困惑:onPause,onStop,onDestroy.

在破坏实例特定资源可能依赖的超类资源之前,首先销毁实例特定资源是有意义的,而不是反过来.但是注释建议不然.我错过了什么?

编辑:由于人们似乎对问题的意图感到困惑,我想知道的是以下哪一项是正确的?为什么?

1.Google建议

    @Override
    protected void onStop() {
      super.onStop();  // Always call the superclass method first

      //my implementation here
    }
Run Code Online (Sandbox Code Playgroud)

另一种方式

    @Override
    protected void onStop() {
       //my implementation here

       super.onStop();  
    }
Run Code Online (Sandbox Code Playgroud)

java android android-lifecycle

83
推荐指数
2
解决办法
2万
查看次数

是否应该对超类方法的调用是第一个语句?

可以在该onActivityResult(int requestCode, int resultCode, Intent data)方法中读取语音识别的结果,如该示例中所示.这个方法在类中重写了相同的方法Activity:为什么对超类方法的调用不是第一个语句?

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it could have heard
        // ...
    }

    super.onActivityResult(requestCode, resultCode, data);
}
Run Code Online (Sandbox Code Playgroud)

android android-lifecycle android-activity

18
推荐指数
1
解决办法
6061
查看次数