简体   繁体   English

Android工作室回到了启动画面

[英]Android studio back goes to splash screen

I have created this simple splash screen ; 我创建了这个简单的启动画面;

public class Splashscreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splashscreen);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {

                Intent i = new Intent(Splashscreen.this, MainActivity.class);
                startActivity(i);

                finish(); } }, 1000);
    }

    }

I declared the splash screen to be the first screen that opens like this; 我宣布启动画面是第一个像这样打开的画面;

   <activity android:name="com.androidhunger.opendagapp.Splashscreen"
        android:noHistory="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"><intent- 
        filter>
        <action android:name="android.intent.action.MAIN" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter></activity>

After the splash screen my mainactivity opens a fragment with menu code inside of it, but I don't think the problem lays there. 在启动画面之后,我的mainactivity打开了一个包含菜单代码的片段,但我不认为问题就在那里。 My problem is, when I open my app and the splash screen is done, and i've loaded my first screen, when I press back once, it takes me to a blank page. 我的问题是,当我打开我的应用程序并且启动画面已完成,并且我已经加载了我的第一个屏幕时,当我按回一次时,它会将我带到一个空白页面。 I can't recreate it here with easely, but I hope someone recognizes the issue. 我不能轻易地在这里重新创建它,但我希望有人认识到这个问题。

you need to clear your activity stack before you start new activity 在开始新活动之前,您需要清除活动堆栈

 Intent i = new Intent(Splashscreen.this, MainActivity.class);
 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
 startActivity(i);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM