Java 如何清除应用程序进程中填充的历史记录 如何清除应用程序进程中填充的历史记录,这里我创建了一个简单的登录应用程序,其中我有两个activites LoginActivity和MainActivity,我使用共享首选项检查用户是否登录,我创建了应用程序类,每次启动应用程序时都会调用它, 我已经在清单中添加了这些代码行
Java 如何清除应用程序进程中填充的历史记录 如何清除应用程序进程中填充的历史记录,这里我创建了一个简单的登录应用程序,其中我有两个activites LoginActivity和MainActivity,我使用共享首选项检查用户是否登录,我创建了应用程序类,每次启动应用程序时都会调用它, 我已经在清单中添加了这些代码行,java,android,Java,Android,android:name=“.FrontScreenApplication” FrontScreenApplication.class如下所示 public class FrontScreenApplication extends Application { public static final String PREFS_NAME = "ApplicationFirstTime"; int PRIVATE_MODE = 0; private static final
android:name=“.FrontScreenApplication”
FrontScreenApplication.class如下所示
public class FrontScreenApplication extends Application {
public static final String PREFS_NAME = "ApplicationFirstTime";
int PRIVATE_MODE = 0;
private static final String PREF_NAME2 = "LoginPref";
private static final String IS_LOGIN = "IsLoggedIn";
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
SharedPreferences pref = getSharedPreferences(PREFS_NAME, 0);
if (!pref.getBoolean("isFirstTime", false)) {
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean("isFirstTime", true);
editor.commit();
Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
SharedPreferences prefs = getSharedPreferences(PREF_NAME2,MODE_PRIVATE);
boolean result = prefs.getBoolean(IS_LOGIN, false);
if (result) {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
清单中的主类是MainActivity,因此首先调用它,当我们返回时,每个活动都显示在backstack LoginAcivity和MainActivity中。您必须设置intent标志intent.flag\u activity\u CLEAR\u TASK。这将解决您的问题
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
或
在AndroidManifest.xml文件中,为FrontScreenApplication活动放置android:noHistory=“true”
或
您可以通过另一种方式完成,只需在启动intent后完成FrontScreenApplication活动
Intent intent = new Intent(Login.this, ReadPhoneNo.class);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
我们在意图中使用FLAG_ACTIVITY_CLEAR_TASK FLAG确切语法如下:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);