How to display only one time Login and then after start application directly in android

后端 未结 6 2146
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 15:34

I am getting trouble in making only one time login... My aim is first user gets login screen.. If he is new user he will register and then login...from then when ever user s

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 15:56

    Use SharedPreferences. contains which tell an key is present or not in SharedPreferences. Change your code as:

       SharedPreferences pref;
       SharedPreferences.Editor editor;
       pref = getSharedPreferences("testapp", MODE_PRIVATE);
       editor = pref.edit();
       if(pref.contains("register"))
        {
             String getStatus=pref.getString("register", "nil");
              if(getStatus.equals("true")){
                 redirect to next activity
               }else{
                //first time
                 editor.putString("register","true");
                 editor.commit();
               ///  show registration page again
               }
        }
        else{ //first time
                 editor = pref.edit();
                 editor.putString("register","true");
                 editor.commit();
               ///  show registration page again
        }
    

提交回复
热议问题