闪屏仅打开一次应用程序启动
有与2活动的应用程序:闪屏和主屏。安装应用程序后它显示扑通一声,然后完成飞溅的活动,并启动的主要活动。然后,我测试3的情况:
There is an application with 2 activities: Splash screen and main screen. After installing application it shows splash, then finishes Splash activity and starts main activity. Then i test 3 scenarios:
-
应用程序启动时,第二个活动显示在屏幕上。我杀了通过DDMS应用程序,启动应用程序再次 - 一切是正确的 - 我再次看到水花四溅,然后第二个活动
App is launched, second activity showed on screen. I kill app process by DDMS, launch app again — everything is right — i see splash again, then second activity
应用程序启动时,第二个活动显示在屏幕上。我preSS返回键,然后再杀掉进程,启动应用程序 - 一切都好过多,它首先推出飞溅
App is launched, second activity showed on screen. I press back key, then kill process, launch application again — everything all right too, it launch splash first
应用程序启动时,第二个活动显示在屏幕上。我preSS home键,然后再杀掉进程,启动应用程序 - 并且有惊喜 - 应用程序启动的第二个活动,逃避飞溅
App is launched, second activity showed on screen. I press home key, then kill process, launch application again — and there is surprise — application starts on second activity, escaping splash.
什么`错了?
有一些人这样的一个问题,但我仍然没有得到答案。
There is some others question like this one, but i still got no answer.
任何人都可以解释这种现象?
Can anybody explain this behavior?
开机画面是不是因为无论如何它给用户的感觉是应用程序是一个附加和休息小幅整个系统生命周期的一个真正的好主意
Splash screens aren't a real good idea anyway since it gives the user the feeling that the application is an add-on and breaks slightly the whole system life cycle.
但如果你真的想有就推出活动启动画面,有两个选择。一个是有一个根 RelativeLayout的
里面的两种观点。一个与的ImageView
并与活动的实际内容的另一个布局内的闪屏。然后,隐藏的ImageView
与您最喜爱的动画。
But if you really want to have a splash screen on the launch Activity, there are two options. One is to have two views inside a root RelativeLayout
. One with the splash screen inside an ImageView
and another layout with the actual content of the activity. Then, hide the ImageView
with your favorite animation.
另外,你可以使用一个片段,而不是内容布局并加载活动
实例(用什么来与的ActivityGroup $完成C $ C>)。
Alternatively, you can use a fragment instead of the content layout and load the Activity
instances (What used to be done with ActivityGroup
).
更新:
好吧,我忘了提及这是为什么在你的应用中发生的。
在任何Android应用程序,我们有一个松散结合的一系列活动和(通常)当我们推出一个新的活动将其添加到活动栈(管理背后的行为)。我常说,因为如果需要的话(launchMode)你可以改变这种行为。
Ok, I forgot to mention why is that happening in your app. In any Android application we have a loosely bound set of activities and (usually) when we launch a new Activity it gets added to an Activity stack (to manage the back behavior). I say usually because you can change that behavior if required (launchMode).
在preSS后退按钮堆栈清空终止活动。在另一方面,当pressing home键,堆栈保存并重新推出时恢复。
When you press the back button the stack is emptied and the activity terminated. On the other hand, when pressing the home button, the stack is saved and restored when relaunching.
Android的生命周期可能会有点头疼的时候,但是一旦你了解它是真正深思熟虑过。
The Android life cycle can be a bit of a headache sometimes, but once you understand it is really well thought through.
下面是一些进一步阅读:活动和任务设计指南
here is some further reading: Activity and Task Design Guidelines