安卓启动画面
我有一个显示启动屏幕的程序。但问题是每当我再次刷新同一页面时,它就会出现。有什么方法可以一次又一次地停止启动屏幕。我希望它只是第一次出现,而不是一次又一次。 谢谢
i have a program that shows a splash screen.But the problem is whenever i refresh same page again it appears.Is there any method to stop splash screen again and again.I want it just comes at first time not again and again.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以你基本上希望每次应用程序启动时闪屏都会出现一次。
这是一种快速但肮脏的方法:
android.app.Application
子类化为MyApp
;AndroidManifest.xml
(
) 中声明该类,以便在应用启动时实例化该类;public static boolean SPLASH_SHOWN = false;
Activity
的onCreate()
中检查是否SPLASH_SHOWN = false< /code>,显示启动画面并将其设置为
true
。So you basically want the splash screen appear once per app launch.
Here's a quick and dirty way:
android.app.Application
as, say,MyApp
;AndroidManifest.xml
(<application android:name=".MyApp" ... >
) so that it would get instantiated at app launch time;public static boolean SPLASH_SHOWN = false;
Activity
'sonCreate()
check ifSPLASH_SHOWN = false
, show splash and set it totrue
.如果您在同一个活动中使用另一个视图布局(主布局)实现启动屏幕 - 例如,首先显示启动屏幕,然后将视图切换到主布局 - 我建议在 onResume 中控制内容视图设置()。
使用布尔变量 (
displayedSplash
) 来记住是否已显示启动屏幕。如果尚未显示(第一次启动 Activity,displayedSplash == false),则将视图设置为闪屏,然后切换到主布局并设置displayedSplash = true
。如果已经显示了(刷新页面,displayedSplash == true),就将view设置为主布局即可。简单闪屏的另一个简单且安全的解决方案是将其实现为一个活动,然后启动主活动。当第二次调用
onResume()
时,只需完成该活动即可。有关详细信息,请参阅此 Wiki。If you implement the splash screen in the same activity with another view layout (the main layout) - for example, display splash screen first, then swich the view to the main layout - I suggest to control the content view setting in
onResume()
.Use a boolean variable (
displayedSplash
) to remember whether the splash screen has been displayed. If it has not been displayed (start the activity the first time, displayedSplash == false), then set the view to the splash screen, after that switch to the main layout and setdisplayedSplash = true
. If it has been displayed (refresh the page, displayedSplash == true), just set the view to the main layout.Another simple and safe solution for simple splash screen is implementing it as an activity, then start the main activity. When the
onResume()
is called the second time, just finish the activity. Please refer to this Wiki for the detail.大多数时候我在启动活动的 onPause() 方法中调用 finish() 方法。这对我来说效果很好
Most of the times I call finish() method inside onPause() method in splash activity. This will work fine for me