[英]Start Second Activity instead of First android
For example, First time i want to start first activity eq: login screen. 例如,第一次我想启动第一个活动eq:登录屏幕。 I validate the screen, if it is success i want to show dashboard screen.
我验证屏幕,如果成功,我想显示仪表板屏幕。 For the second time, I directly want to show dashboard screen instead of login.
第二次,我直接想显示仪表板屏幕而不是登录。 Is it possible to directly start
是否可以直接启动
In First Activity If login is successful then store flag value is true in sharedpreferences and next time check if sharedpreferences value is true in splashscreenactivity then directly open dashboard activity, Use below code to save shared preferences on login successful. 在“首次活动”中,如果登录成功,则存储标志值在sharedpreferences中为true,并且下次检查splashscreenactivity中的sharedpreferences值是否为true,然后直接打开仪表板活动,使用以下代码在登录成功时保存共享首选项。
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Flag Value","True");
editor.commit();
For get SharedPreferences data into SplashScreen Activity:- 要将SplashScreen活动中的SharedPreferences数据获取:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String FlagValue = preferences.getString("Flag Value","");
if(FlagValue.equals("True")){
Intent intent=new Intent(this, DashBoard_Activity.class);
startActivity(intent);
}
use SharedPreferences in your project. 在您的项目中使用SharedPreferences。
put your strings in preferences 将您的字符串放在首选项中
Editor edit = preferences.edit();
edit.putString("pref_empId", "1");
edit.putString("pref_userName", "kiran");
edit.putString("pref_userType", "ADMIN");
edit.commit();
next time check 下次检查
pref_userName = preferences.getString("pref_userName", "n/a");
pref_empId = preferences.getString("pref_empId","n/a");
pref_userType = preferences.getString("pref_userType","n/a");
if(!pref_userName.equals("") || !pref_userName.equals("n/a"))
{
// go to login activity
}
else
{
// dash board activity
}
You can use Preferances for checking weather it is a valid user are not. 您可以使用“首选项”检查不是有效用户的天气。 if it is then you can allow to enter into the second Activity.
如果是,那么您可以允许进入第二个活动。
One solution is to make a dummy activity. 一种解决方案是进行虚拟活动。 All it does is if person is logged in or not.
它所做的就是是否已登录人员。 If he isn't launch the login activity, else launch the dashboard activity.
如果他没有启动登录活动,则启动仪表板活动。
I usually put a splash screen here for the app and show the app's name or something with a nice image. 我通常在这里为应用程序放置一个启动屏幕,并显示应用程序的名称或带有漂亮图像的内容。
Follow The Sequence like 1. login Screen 2. Before Opening the Validate Screen finish the Login Screen 3. After Successful validation open dashword screen 按照以下步骤进行操作:1.登录屏幕2.在打开“验证”屏幕之前,完成“登录”屏幕3.在成功验证之后,打开破折号屏幕
Intent in = new Intent(Login.this,Validation.class);
startActivity(in);
this.finish();
Intent in = new Intent(Validation.this,Dashword.class);
startActivity(in);
this.finish();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.