Android onRestart调用时机

onRestart调用时机

官方阐述:

onRestart

void onRestart ()

Called after onStop() when the current activity is being re-displayed to the user (the user has navigated back to it). It will be followed by onStart() and then onResume().
For activities that are using raw Cursor objects (instead of creating them through managedQuery(android.net.Uri, String[], String, String[], String), this is usually the place where the cursor should be requeried (because you had deactivated it in onStop().
Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.
If you override this method you must call through to the superclass implementation.

个人解读

官方解释强调再次显示activiy时,onRestart会被调用。再次显示有2种情况:

    1. activity由不可见变为可见
    1. 已经存在activity实例,再次启动activity时
      官方强调,如果复写该方法,应该在方法内调用父类方法,否则会抛出异常。
      所以正确的代码编写是:
@Override
protected void onRestart() {
    // If you override this method you must call through to the superclass implementation
    super.onRestart();
}



转自:https://www.jianshu.com/p/45e8af577e3f

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值