Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 starts the application he should directly redirect to main activity that is to skip the login page..please friends help me out from this problem..please post me any tutorials or any code...please tell me how to modify in manifest file also...

I am using like this in login activity but i didn't achieve my task.

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
like image 735
user3304617 Avatar asked Feb 24 '14 06:02

user3304617


People also ask

How to show activity only one time in Android?

It is important to check that the first activity which opens when the app is launched is MainActivity. java (The activity which we want to appear only once). For this, open the AndroidManifest. xml file and ensure that we have the intent-filter tag inside the activity tag that should appear just once.

How do I keep Android apps logged in?

When users log in to your application, store the login status into sharedPreference and clear sharedPreference when users log out. Check every time when the user enters into the application if user status from shared Preference is true then no need to log in again otherwise direct to the login page.

How to store login details in SharedPreferences in Android?

Write to Shared Preferences To store data in a shared preference file, we need an editor to edit and save the changes in the SharedPreferences object. Following is the code snippet to store the data in shared preference file using an editor. SharedPreferences sharedPref = getPreferences(Context. MODE_PRIVATE);

How to launch activity only once when Android app is opened?

This example demonstrates about How to launch activity only once when Android app is opened for the first time. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

What is the use of a login screen in an app?

It may be used for getting user’s login information or other one-time information so that the user does not need to go through the hassles of entering their information every time they open the app. It may be used to display some information regarding the app which the user might not wish to see every time.

What happens when you start an app from a blank screen?

When your application launches, the blank starting window remains on the screen until the system finishes drawing the app for the first time. At that point, the system process swaps out the starting window for your app, allowing the user to start interacting with the app.

How long does it take Android apps to start up?

Android vitals considers your app's startup times excessive when the app's: Cold startup takes 5 seconds or longer. Warm startup takes 2 seconds or longer. Hot startup takes 1.5 seconds or longer.


1 Answers

Implement your SharedPreferences this way:

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
}
like image 88
M D Avatar answered Nov 05 '22 08:11

M D