android 退出时闪屏很奇怪

发布于 2024-10-19 06:52:56 字数 1055 浏览 5 评论 0原文

我为我的 Android 应用程序创建了一个闪屏。我沿着路线走下去,它自己的活动在启动线程中显示自己,然后加载“MainMenu”活动。 这工作正常,直到我想退出该应用程序。 当我点击“后退按钮”时,我看到了主菜单窗口。当我第二次点击“后退按钮”时..我没有看到启动画面,但我再次看到了主菜单。额外的“返回”将结束应用程序。

不好,有什么关于如何避免这种行为的好的提示吗? 当然,最好的方法是在“主菜单”中点击“返回”时直接结束应用程序,但我想我随后需要重新建模启动屏幕以成为该活动的一部分?

飞溅代码

   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread splashThread = new Thread() {
       @Override
       public void run() {
          try {
             Log.d("Trying","Tries");
             int waited = 0;
             while (waited < 5000) {
                sleep(100);
                waited += 100;
             }
          } catch (InterruptedException e) {
              Log.d("Catching", e.toString());
          } finally {
             finish();
             Intent i = new Intent(UEABB.this,MainMenu.class);
             UEABB.this.startActivity(i);
             startActivity(i);

          }
       }
    };
    splashThread.start();
 }

问候

I have created a splashscreen for my android app. I went down the route with an activity of it's own displaying itself in a splashthread and then loading the "MainMenu" acitivty.
This works alright, until I want to quit the app.
When I hit the "back button" I see the MainMenu window. When I hit the "back button" a second time .. I don't see the splashscreen I see the MainMenu once more. An additional "back" will end the app.

Not nice, are there any good hints on how to avoid that behaviour?
Best of all would of course be to end the app directly when hitting "back" form the "MainMenu" but I guess I then need to re-model the splashscreen to be a part of that activity instead?

Splashcode

   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread splashThread = new Thread() {
       @Override
       public void run() {
          try {
             Log.d("Trying","Tries");
             int waited = 0;
             while (waited < 5000) {
                sleep(100);
                waited += 100;
             }
          } catch (InterruptedException e) {
              Log.d("Catching", e.toString());
          } finally {
             finish();
             Intent i = new Intent(UEABB.this,MainMenu.class);
             UEABB.this.startActivity(i);
             startActivity(i);

          }
       }
    };
    splashThread.start();
 }

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

浪菊怪哟 2024-10-26 06:52:56

尝试在您的manifest.xml 中的SplashScreen Activity 上显式设置android:noHistory="true"。我在设计“新增内容”活动时遵循了类似的方法。

<activity android:name=".activities.WhatsNewActivity"
    android:label="Version History" android:noHistory="true">
    <intent-filter>
       <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

不过,一旦切换到另一个 Activity,您就应该调用 finish()

Try to explicitly set the android:noHistory="true" on the SplashScreen Activity in your manifest.xml. I followed a similar approach when designing my "What's New" Activity.

<activity android:name=".activities.WhatsNewActivity"
    android:label="Version History" android:noHistory="true">
    <intent-filter>
       <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Nevertheless you should call finish() once you switch to another activity.

画离情绘悲伤 2024-10-26 06:52:56

您的splashthread 活动应在启动MainMenu 活动后立即调用finish()。这会将其从堆栈中删除,并且不会干扰退出应用程序。

除非您在事件处理程序中使用后退键,否则我想不出任何其他可能导致此行为的事情。也许您可以发布splashthread 的代码。

Your splashthread activity should call finish() immediately after starting the MainMenu activity. That will remove it from the stack and it shouldn't interfere with exiting the app.

Unless you are consuming the back key in an event handler, I can't think of anything else off the top of my head that could cause this behavior. Perhaps you could post the code for splashthread.

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