oncreate 在应用程序进入前台时被调用
oncreate is getting called when application comes to foreground
我有 SplashScreen Activity 和 MainActivity。一旦 SplashScreen 超时,我正在调用
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
它将我带到 Mainactivity 的 onCreate。现在我按下设备主页按钮并使应用程序长时间保持在背景中,当我通过单击启动器图标将应用程序带到前台时,它会将我带到 MainActivity 的 onCreate。在这里,我怀疑设备是否正在从应用程序后台杀死我的应用程序,那么它应该从 SplashScreen Activity 而不是 MainActivity 开始。我没有在 Manifest.xml 中设置任何启动模式标签。你能帮帮我吗
将 manifest.xml
中的 Intent 过滤器设置为 SplashActivity
如下
<activity
android:name=".activity.SplashActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
现在,如果您的应用程序将首先在应用程序启动时搜索启动画面。还要记住,当您在 activity 上调用 - finish() ;
时,activity 已被删除来自 Stack.So 当您再次返回应用程序时,您将能够看到您的 HomeActivity
。
Now I press device home button and keeps the app in backgroung for long time and when I am bringing the app to the foreground by clicking on Launcher icon it is taking me to the onCreate of MainActivity.
是的,这是预期的行为。如果该应用程序在后台运行的时间足够长,以至于 OS 终止了您的应用程序进程,您的 MainActivity 将需要完成其完整的创建过程,包括 onCreate()
(尽管您应该看到 savedInstanceState
在此 re-creation) 期间,捆绑包是 non-null。
Here I am doubting if device is killing my app from Application backstack then it should start from SplashScreen Activity instead of MainActivity.
我认为您误解了 OS 终止应用进程的含义。这并不意味着你的应用已经"quit",也不意味着你的应用会像第一次启动时一样从头开始。事实上,它显然 而不是 应该看起来像是第一次启动。主要思想是 OS 杀死你的应用进程不应该是用户意识到的事情;他们应该从中断的地方开始。
我有 SplashScreen Activity 和 MainActivity。一旦 SplashScreen 超时,我正在调用
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
它将我带到 Mainactivity 的 onCreate。现在我按下设备主页按钮并使应用程序长时间保持在背景中,当我通过单击启动器图标将应用程序带到前台时,它会将我带到 MainActivity 的 onCreate。在这里,我怀疑设备是否正在从应用程序后台杀死我的应用程序,那么它应该从 SplashScreen Activity 而不是 MainActivity 开始。我没有在 Manifest.xml 中设置任何启动模式标签。你能帮帮我吗
将 manifest.xml
中的 Intent 过滤器设置为 SplashActivity
如下
<activity
android:name=".activity.SplashActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
现在,如果您的应用程序将首先在应用程序启动时搜索启动画面。还要记住,当您在 activity 上调用 - finish() ;
时,activity 已被删除来自 Stack.So 当您再次返回应用程序时,您将能够看到您的 HomeActivity
。
Now I press device home button and keeps the app in backgroung for long time and when I am bringing the app to the foreground by clicking on Launcher icon it is taking me to the onCreate of MainActivity.
是的,这是预期的行为。如果该应用程序在后台运行的时间足够长,以至于 OS 终止了您的应用程序进程,您的 MainActivity 将需要完成其完整的创建过程,包括 onCreate()
(尽管您应该看到 savedInstanceState
在此 re-creation) 期间,捆绑包是 non-null。
Here I am doubting if device is killing my app from Application backstack then it should start from SplashScreen Activity instead of MainActivity.
我认为您误解了 OS 终止应用进程的含义。这并不意味着你的应用已经"quit",也不意味着你的应用会像第一次启动时一样从头开始。事实上,它显然 而不是 应该看起来像是第一次启动。主要思想是 OS 杀死你的应用进程不应该是用户意识到的事情;他们应该从中断的地方开始。