相关疑难解决方法(0)

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

可以在该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
查看次数

生命周期方法的Android实现可以在做任何工作后调用超类实现吗?

Android文档中,我们有:

注意:在执行任何工作之前,您对这些生命周期方法的实现必须始终调用超类实现...

但我已经看到过代码放在超类方法之后的情况,特别是对于像onPause(),onStop(),onDestroy()这样的方法,例如:

@Override
protected void onPause() {
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
    super.onPause();
} 
Run Code Online (Sandbox Code Playgroud)

http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html#ownreceiver_localbroadcastmanager

它在两种方式都有效.那么,在调用超类方法之后将代码置于o之前有什么区别?什么是正确的方法?

lifecycle android android-activity

12
推荐指数
2
解决办法
2498
查看次数