Run activity only once, then always run the main one

后端 未结 4 1829
北海茫月
北海茫月 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:42

    SharedPreferences sp = getSharedPreferences("checking",MODE_PRIVATE);
    
    String data = sp.getString("check", "");
    
    if (data.equals("success")) {
    
    //one time proccess code
    
    //with follow code
    
    SharedPreferences sp= getSharedPreferences("checking",MODE_PRIVATE);
    
    Editor e1 = sp.edit();
    
    e1.putString("check","success");
    
    e1.commit();
    
    
    } else {
    
    // code for main
    
     Intent intent = new Intent(this, MainActivty.class);
     startActivity(intent);
    
    }
    

提交回复
热议问题