安卓启动画面

发布于 2024-08-21 23:40:46 字数 88 浏览 2 评论 0原文

我有一个显示启动屏幕的程序。但问题是每当我再次刷新同一页面时,它就会出现。有什么方法可以一次又一次地停止启动屏幕。我希望它只是第一次出现,而不是一次又一次。 谢谢

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧竹 2024-08-28 23:40:46

所以你基本上希望每次应用程序启动时闪屏都会出现一次。
这是一种快速但肮脏的方法:

  1. android.app.Application 子类化为 MyApp;
  2. AndroidManifest.xml () 中声明该类,以便在应用启动时实例化该类;
  3. 给它一个 public static boolean SPLASH_SHOWN = false;
  4. 现在,在您的 ActivityonCreate() 中检查是否 SPLASH_SHOWN = false< /code>,显示启动画面并将其设置为true

So you basically want the splash screen appear once per app launch.
Here's a quick and dirty way:

  1. Subclass android.app.Application as, say, MyApp;
  2. Declare that class in AndroidManifest.xml (<application android:name=".MyApp" ... >) so that it would get instantiated at app launch time;
  3. Give it a public static boolean SPLASH_SHOWN = false;
  4. Now, in your Activity's onCreate() check if SPLASH_SHOWN = false, show splash and set it to true.
面如桃花 2024-08-28 23:40:46

如果您在同一个活动中使用另一个视图布局(主布局)实现启动屏幕 - 例如,首先显示启动屏幕,然后将视图切换到主布局 - 我建议在 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 set displayedSplash = 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.

几味少女 2024-08-28 23:40:46

大多数时候我在启动活动的 onPause() 方法中调用 finish() 方法。这对我来说效果很好

Most of the times I call finish() method inside onPause() method in splash activity. This will work fine for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文