有人可以给我一个如何在课堂上正确注销LocalBroadcastManager
接收者的例子吗?Activity
Android 开发者培训建议这样做:
@Override
public void onPause() {
super.onPause(); // Always call the superclass method first
// When I should to unregister LocalBroadcastManager Receiver before or after super.onPause()?
}
和
@Override
public void onDestroy() {
// If the DownloadStateReceiver still exists, unregister it and set it to null
if (mDownloadStateReceiver != null) {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mDownloadStateReceiver);
mDownloadStateReceiver = null;
}
...
// Must always call the super method at the end.
super.onDestroy();
}
我看到了谷歌的例子,但我不明白什么时候应该在之前或之后取消注册LocalBroadcastManager
接收器super.onPause();
以及在之前或之后的方法onDestroy
中super.onDestroy();
?
提前致谢!
更新:我在方法中
注册LocalBroadcastManager
接收器onResume()
!