我创建了这个简单的启动屏幕;
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 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>
在启动屏幕之后,我的主要 Activity 打开了一个 fragment ,其中包含菜单代码,但我认为问题不在那里。我的问题是,当我打开我的应用程序并且启动画面完成,并且我已经加载了第一个屏幕时,当我按回一次时,它会将我带到一个空白页面。我无法在这里轻松地重新创建它,但我希望有人认识到这个问题。
最佳答案
在开始新 Activity 之前,您需要清除 Activity 堆栈
Intent i = new Intent(Splashscreen.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
关于java - Android Studio 返回到初始屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56317796/