如何在不启动新活动的情况下清除 Android 上的先前活动 [英] How to clear previous Activity on Android without start new Activity
本文介绍了如何在不启动新活动的情况下清除 Android 上的先前活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想清除以前的活动,但不想在 android 上启动新活动.
I want to clear previous activity but without start new activity on android.
通常我在清洁时使用此代码
Usually I use this code when change with cleaning
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
但是如果我不想改变活动怎么办?也许有人可以帮助我..
but how if I don't want to change activities? maybe someone can help me..
推荐答案
Step1:Create a drawable:
Step1:Create a drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/darker_gray" />
<item>
<bitmap
android:gravity="center"
android:src="@drawable/img_splash" />
</item>
代码链接:splash_theme_bg.xml
步骤 2:创建样式
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_theme_bg</item>
</style>
代码链接:styles.xml
Step3:在AndroidManifest.xml中设置样式
Step3: Set style in AndroidManifest.xml
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
代码链接:AndroidManifest.xml
如果您仍然卡在任何地方,请告诉我.快乐编码!
这篇关于如何在不启动新活动的情况下清除 Android 上的先前活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文