SoFunction
Updated on 2025-04-05

Android determines whether the program is started for the first time

This article shares the specific code for determining whether the Android program is launched for the first time for your reference. The specific content is as follows

public class Welcome extends Activity {
  private final long SPLASH_LENGTH = 2000;
  Handler handler = new Handler();

  public void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    setContentView(.farst_img);
    
    //Define a setting record how many times the APP is started!  !  !    SharedPreferences setting = getSharedPreferences(".hr_jie", 0);
    Boolean user_first = ("FIRST", true);
    if (user_first) {// Jump to the welcome page for the first time      ().putBoolean("FIRST", false).commit();
      tiaozhuanzhu();
    } else {//If it is the second startup, it will jump to the main page directly      tiaozhuanfu();
    }
  }
  
  public void tiaozhuanzhu(){ 
  (new Runnable() { //Use handler's postDelayed to achieve delay jump     
      public void run() {  
        Intent intent = new Intent(, Welcome_four.class);  
        startActivity(intent);  
        finish();    
      }  
    }, SPLASH_LENGTH);//Skip to the main interface of MainActivity in 2 seconds}
  
  public void tiaozhuanfu(){ 
  (new Runnable() {//Use handler's postDelayed to achieve delay jump     
      public void run() {  
        Intent intent = new Intent(, );  
        startActivity(intent);  
        finish();    
      }  
    }, SPLASH_LENGTH);//Redirect to the application welcome interface in 2 seconds}
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.