On successful signup of login you have to store data in SharedPreferences
.
AppTypeDetails is class for SharedPreferences.
AppTypeDetails.getInstance(SignUpActivity.this).setEmail(<Your Email ID>);
AppTypeDetails.getInstance(SignUpActivity.this).setPassword(<Your Password>);
AppTypeDetails.java
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class AppTypeDetails {
private SharedPreferences sh;
private AppTypeDetails() {
}
private AppTypeDetails(Context mContext) {
sh = PreferenceManager.getDefaultSharedPreferences(mContext);
}
private static AppTypeDetails instance = null;
/**
*
* @param mContext
* @return {@link AppTypeDetails}
*/
public synchronized static AppTypeDetails getInstance(Context mContext) {
if (instance == null) {
instance = new AppTypeDetails(mContext);
}
return instance;
}
// get username
public String getEmail() {
return sh.getString("email", "");
}
public void setEmail(String email) {
sh.edit().putString("email", email).commit();
}
// get password
public String getPassword() {
return sh.getString("password", "");
}
public void setPassword(String password) {
sh.edit().putString("password", password).commit();
}
public void clear() {
sh.edit().clear().commit();
}
}
Now check below code in splash screen.
String email = AppTypeDetails.getInstance(SplashScreen.this).getEmail();
String pass = AppTypeDetails.getInstance(SplashScreen.this).getPassword();
if (email.trim().isEmpty() && pass.trim().isEmpty()) {
Intent intent = new Intent(SplashScreen.this, Login.class);
startActivity(intent);
} else {
Intent intent = new Intent(SplashScreen.this, MainScreenTabHost.class);
startActivity(intent);
}
For clear SharedPreferences
:
Call clear() method on logout.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…