如何清除应用程序进度中填充的历史记录

时间:2014-11-24 07:21:00

标签: java android

  1. 如何清除在应用程序进度中填充的历史记录,这里创建一个简单的登录应用程序,我有两个活动LoginActivity和MainActivity,我使用共享首选项来检查用户是否登录,我已经申请了每次启动应用程序时都会调用的类, 我在清单
  2. 中添加了这些代码行

    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中。

2 个答案:

答案 0 :(得分:1)

您必须设置意图标记Intent.FLAG_ACTIVITY_CLEAR_TASK。这将解决您的问题。

      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)

OR

在AndroidManifest.xml文件中输入android:noHistory =" true"用于FrontScreenApplication活动。

OR

您可以通过其他方式完成此操作,只需在启动意图后完成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();

答案 1 :(得分:0)

我们在intent精确语法中使用FLAG_ACTIVITY_CLEAR_TASK标志如下:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);