开发者

android splashcreen weird when quitting

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 {
   开发者_JAVA百科          finish();
             Intent i = new Intent(UEABB.this,MainMenu.class);
             UEABB.this.startActivity(i);
             startActivity(i);

          }
       }
    };
    splashThread.start();
 }

Regards


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜