Run activity only once, then always run the main one

后端 未结 4 1734
北海茫月
北海茫月 2021-01-16 20:11

As the title says, Scenario is: On first time using the app, Show Screen A. Once you are done with screen A, the button will lead to you Screen B. From now on and forever, t

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 20:53

    All you have to check like this

     SharedPreferences prefs = getSharedPreferences("mySHaredpref", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        boolean isFirst = prefs.getBoolean("isfirstTime", true);
        if(isFirst) {
            Intent intent = new Intent(this, ActivtyA.class);
            editor.putBoolean(KEY_IS_FIRST_TIME, false);
            editor.commit();
            startActivity(intent);
        }
        else{
          Intent intent = new Intent(this, MainActivty.class);
          startActivity(intent);
        }
    

提交回复
热议问题