采用android系统的标志,以便从从那里应用程序被关闭相同的活动启动 [英] Using flags in android so to start from the same activity from where the app was closed

查看:124
本文介绍了采用android系统的标志,以便从从那里应用程序被关闭相同的活动启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个应用程序在注册页面3号。当用户在第一页登记并保存,这是不言而喻的第二页等。如果假设用户只注册的第一页上,并关闭了应用程序,然后当过用户打开应用程序应该带给用户登记的第二页。如何做到这一点?

I am creating an app in which the registration pages are 3 in number. When the user registers on the first page and saves it, it goes to the second page and so on. If suppose the user has only registered on the first page and has closed the app then when ever the user opens the app it should bring the user to the second page of registration. How to do this?

推荐答案

假设你的拳头注册页面包含电子邮件地址和密码。
如果第一页注册成功,则设置第一页的数据,共享preferences 象下面这样。

Suppose your fist signup page contain email and password. If firstpage signup is successful then set data of first page in SharedPreferences like below.

AppTypeDetails是共享preferences类。

 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 close your app and open again

现在,查看以下code在启动画面。

Now check below code in splash screen.

String email = AppTypeDetails.getInstance(SplashScreen.this).getEmail();
String pass = AppTypeDetails.getInstance(SplashScreen.this).getPassword();

if (email == null && pass == null) {

    // Open First SignUp page

} else {
    // Open Second SignUp page
}

和你继续。

如果注册页面2成功,则保存第2页的数据,共享preferences 并为您在闪屏第一页和第二页的数据。
如果第一页和第二页的数据不为空,然后直接打开第3页。

If signup page 2 is successful then save data of 2nd page in SharedPreferences and check data of first page and second page in splash screen. If data of first page and second page is not null then directly open 3rd page.

对于明确共享preferences

For clear SharedPreferences :

呼叫clear()方法。

Call clear() method on logout.

这篇关于采用android系统的标志,以便从从那里应用程序被关闭相同的活动启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆