java Android studio返回初始屏幕
我创建了这个简单的启动屏幕
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);
}
}
我宣布启动屏幕是第一个这样打开的屏幕
<activity 安卓:name="com.安卓hunger.opendagapp.Splashscreen"
安卓:noHistory="true"
安卓:theme="@style/Theme.AppCompat.Light.NoActionBar"><intent-
filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<action 安卓:name="安卓.intent.action.VIEW" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter></activity>
启动屏幕后,我的mainactivity打开了一个包含菜单代码的片段,但我认为问题不在这里。我的问题是,当我打开我的应用程序,启动屏幕完成后,我加载了我的第一个屏幕,当我按一次back时,它会把我带到一个空白页面。我不能轻松地在这里重新创建它,但我希望有人认识到这个问题
# 1 楼答案
在开始新活动之前,需要清除活动堆栈