How to display Login only once, and then after launching the application directly in android

I am having problems creating only one login ... My goal is that the first user gets a login screen. If he is a new user, he will register and then register ... from the moment the user starts the application, he must directly redirect to the main activity in order to skip the login page. Friends can help me solve this problem. Please write me any tutorials or any code ... please tell me how to change the manifest file ...

I use this in login activity, but I have not reached my goal.

SharedPreferences pref; SharedPreferences.Editor editor; pref = getSharedPreferences("testapp", MODE_PRIVATE); editor = pref.edit(); editor.putString("register","true"); editor.commit(); String getStatus=pref.getString("register", "nil"); if(getStatus.equals("true")) // redirect to next activity else // show registration page again 
+6
source share
5 answers

check here

http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/

A very good example of session management in an Android app.

+5
source

SharedPreferences your SharedPreferences as follows:

 Boolean isFirstTime; SharedPreferences app_preferences = PreferenceManager .getDefaultSharedPreferences(Splash.this); SharedPreferences.Editor editor = app_preferences.edit(); isFirstTime = app_preferences.getBoolean("isFirstTime", true); if (isFirstTime) { //implement your first time logic editor.putBoolean("isFirstTime", false); editor.commit(); }else{ //app open directly } 
+6
source

Use SharedPreferences. contains that indicate that the 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 } 
+2
source

You can visit my blog

http://upadhyayjiteshandroid.blogspot.in/2013/01/android-working-with-shared-preferences.html

hope you get an answer and understanding clearly

 Boolean flag; SharedPreferences applicationpreferences = PreferenceManager .getDefaultSharedPreferences(MainActivity.this); SharedPreferences.Editor editor = applicationpreferences .edit(); flag = applicationpreferences .getBoolean("flag", false); if (flag) { ///second time activity }else{ //first time editor.putBoolean("flag", true); editor.commit(); } 
0
source

Check out โ€œSession Managementโ€ in Android , which shows how you can control the login if the user is already registered in the application or not, and switch the user accordingly.

Hope this helps you.

0
source

All Articles