Activity be killed when press HOME only in release mode

后端 未结 1 1743
攒了一身酷
攒了一身酷 2021-01-20 02:02

First, I have two activities: Splash and MainActivity ( only support portrait). In MainActivity, I have many fragments use Slide menu. I want to keep current fragment when u

相关标签:
1条回答
  • 2021-01-20 02:37

    Issue has been fixed by using FLAG_ACTIVITY_NEW_TASK when navigate from Splash to Main activity. I just wonder why it can work in debug mode (Reproduce install from apk like release mode). Here is my workable code for anyone has same issues:

     Intent intent = new Intent(SplashActivity.this, MainActivity.class);
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     finish();
     startActivity(intent);
    

    Update: many thanks to David Wasser, so the right answer should like this:

    // SplashActivity
     if(!isTaskRoot()) {
        finish();
        return;
     }
    

    Reference: Re-launch of Activity on Home button, but...only the first time

    0 讨论(0)
提交回复
热议问题