Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am developing an android app in which I am signing up with my mobile number on splash screen . What I want is that signing up should be neccessary only once and first time at the time of app installation. After installing the app, app should open from another activity , not the from splash screen. how it is possible.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
225 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...