1个用户多个帐户1个Android应用程序将数据从登录活动传输到闪屏活动
我正在开发一个应用程序,用户必须能够在他的帐户之间进行切换。截至目前,我可以允许一个帐户登录的应用程序。我如何允许用户创建另一个帐户,然后在我的Android应用程序中切换它们?1个用户多个帐户1个Android应用程序将数据从登录活动传输到闪屏活动
更新: -
I'm able to auth by Google button (firebase)
I want to do something like this in my app!
在我login.class我保存,我从火力得到了UID的值。现在我想将这些数据发送到我的启动画面,它将检查uid == null是否将重定向到登录,如果uid!= null,那么它将重定向到MainActivity。
login.class
String MyPREFERENCES = "MyPrefs" ;
String uid = "uidKey";
SharedPreferences sharedpreferences = login.this.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("uid", UID);
editor.putBoolean("is_logged_before",true); //this line will do trick
editor.commit();
Toast.makeText(login.this,"uid:"+UID,Toast.LENGTH_LONG).show();
String uid1 = sharedpreferences.getString("uid", "");
Log.i("shareduser",uid1);
Intent i = new Intent(login.this,splashScreen.class);
i.putExtra("message",uid1);
startActivity(i);
溅射屏幕
公共类溅射屏幕延伸活动{
private static int SPLASH_TIME_OUT = 2000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
/*Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");
Log.i("received uid",message);*/
Intent homeIntent = new Intent(splashScreen.this, login.class);
startActivity(homeIntent);
finish();
}
},SPLASH_TIME_OUT);
}
}
的范围你的答案很广泛。请只询问与编程相关的真正疑虑。
看起来你需要实现用户的自动登录。为此,您需要使用共享首选项。
成功登录用户后,将用户名和密码存储在共享首选项中。
然后当用户再次尝试登录时,您需要检查sharedPref以检查用户名和密码。 此外,它还取决于您正在实施的身份验证的类型,因为您还可以获取用户的会话ID。
检查这个answer为
也为帐户选择器检查此answer
我可以验证用户。我只想在一个Android应用程序中使用2个帐户.Instagram允许您在帐户之间切换。我想要做那样的事情! –
你的问题解决了吗? –
是的,如果你想支持多个帐户你需要记住用户名和密码。这可以通过共享首选项来实现。点击添加账户菜单后,用户返回登录页面,然后存储用户名和密码。如果用户从共享首选项注销清除数据 –
提供一些您目前的实施步骤 –
我已经更新我的查询。 –