加入收藏 | 设为首页 | 会员中心 | 我要投稿 我爱故事小小网_铜陵站长网 (http://www.0562zz.com/)- 视频终端、云渲染、应用安全、数据安全、安全管理!
当前位置: 首页 > 教程 > 正文

Android Launcher 会onCreate 两次的理由

发布时间:2021-12-18 14:53:28 所属栏目:教程 来源:互联网
导读:com.Android.server.am.ActivityStack /** * Make sure the given activity matches the current configuration. Returns * false if the activity had to be destroyed. Returns true if the * configuration is the same, or the activity will remain run

com.Android.server.am.ActivityStack  
   /**
    * Make sure the given activity matches the current configuration.  Returns
    * false if the activity had to be destroyed.  Returns true if the
    * configuration is the same, or the activity will remain running as-is
    * for whatever reason.  Ensures the HistoryRecord is updated with the
    * correct configuration and all other bookkeeping is handled.
    */  
   final boolean ensureActivityConfigurationLocked(ActivityRecord r,  
           int globalChanges) {  
       ...  
       if ((changes&(~r.info.configChanges)) != 0) {  
           // Aha, the activity isn't handling the change, so DIE DIE DIE.   
           r.configChangeFlags |= changes;  
           r.startFreezingScreenLocked(r.app, globalChanges);  
           if (r.app == null || r.app.thread == null) {  
               if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,  
                       "Switch is destroying non-running " + r);  
               destroyActivityLocked(r, true);  
           } else if (r.state == ActivityState.PAUSING) {  
               // A little annoying: we are waiting for this activity to   
               // finish pausing.  Let's not do anything now, but just   
               // flag that it needs to be restarted when done pausing.   
               if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,  
                       "Switch is skipping already pausing " + r);  
               r.configDestroy = true;  
               return true;  
           } else if (r.state == ActivityState.RESUMED) {  
               // Try to optimize this case: the configuration is changing   
               // and we need to restart the top, resumed activity.   
               // Instead of doing the normal handshaking, just say   
               // "restart!".   
               if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,  
                       "Switch is restarting resumed " + r);  
                 
               relaunchActivityLocked(r, r.configChangeFlags, true);  
               r.configChangeFlags = 0;  
           } else {  
               if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,  
                       "Switch is restarting non-resumed " + r);  
               relaunchActivityLocked(r, r.configChangeFlags, false);  
               r.configChangeFlags = 0;  
           }  
             
           // All done...  tell the caller we weren't able to keep this   
           // activity around.   
           return false;  
       }  
       ...  
      }  
注意以上代码中的第13行和第41行
Why:
 
        系统启动后,搜索到可用移动网络会触发 config changes : mcc | mnc
 
        “mcc“   The IMSI mobile country code (MCC) has changed — that is, a SIM hasbeen detected and updated the MCC.移动国家号码,由三位数字组成,每个国家都有自己独立的MCC,可以识别手机用户所属国家。
        “mnc“   The IMSI mobile network code (MNC) has changed — that is, a SIM hasbeen detected and updated the MNC.移动网号,在一个国家或者地区中,用于区分手机用户的服务商。
 
 
HowTo:
 
<activity android:name="Launcher" android:launchMode="singleTask" android:configChanges="mcc|mnc|keyboardHidden|orientation">

(编辑:我爱故事小小网_铜陵站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读