Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

How to start an android app from two activity

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...