简体   繁体   English

启动Second Activity而不是First android

[英]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.

相关问题 如何首先启动特定的Android活动 - How to start a particular Android activity first 选择按钮后,我的第二个android活动将无法启动 - My second android activity wont start when button is selected 意图:开始一个活动,无法开始第二个活动 - Intent : To start an activity, unable to start the second activity 在Android中向“第二个活动”添加了一个“返回至第一个”按钮。 现在,导航到第二个活动时应用程序崩溃 - Added A Button To Second Activity In Android To Return To First. Now App Crashes When Navigating To Second Activity 我可以在没有 getParcelableExtra 的情况下使用第一个活动中收到的意图开始第二个活动吗? - Can I start a second activity with an intent received in the first activity without getParcelableExtra? 重写Android功能以启动活动而不是dsplaying文本 - Rewrite Android Function to start an Activity instead of dsplaying text Android:应用程序从一个活动跳到第二个活动,而对第一个活动没有任何操作 - Android: App jumping from one activity to second without any action on first activity 显示有关第二个活动中设置的第一个活动的数据 - Displaying data on first activity that is set in the second activity 将数据从第二个活动移到第一个活动 - Move Data from Second Activity to first Activity 在 Android 中的另一个活动中开始活动 - Start activity in another activity in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM