Showing the setup screen only on first launch in android

后端 未结 2 615
旧巷少年郎
旧巷少年郎 2021-01-03 09:18

I am making an android application but i can\'t figure out how i can make the setup screen show up only the first time. This is how the application is going to work: User la

2条回答
  •  佛祖请我去吃肉
    2021-01-03 09:55

    Use SharedPreferences to test whether its the first start or not.

    Note: The below code was not tested.

    In your onCreate (or whereever you want to do things depending on first start or not), add

    // here goes standard code 
    
    SharedPreferences pref = getSharedPreferences("mypref", MODE_PRIVATE);
    
    if(pref.getBoolean("firststart", true)){
       // update sharedpreference - another start wont be the first
       SharedPreferences.Editor editor = pref.edit();
       editor.putBoolean("firststart", false);
       editor.commit(); // apply changes
    
       // first start, show your dialog | first-run code goes here
    }
    
    // here goes standard code
    

提交回复
热议问题