Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何创建启动屏幕以管理活动意图_Android_Android Intent_Splash Screen - Fatal编程技术网

Android 如何创建启动屏幕以管理活动意图

Android 如何创建启动屏幕以管理活动意图,android,android-intent,splash-screen,Android,Android Intent,Splash Screen,我想在我的应用程序中创建3个活动。第一个是loginActivity,第二个是formActivity(包含用户填写的表单),第三个是ProfileActivity。我想按以下方式安排这些活动- 用户需要在首次启动应用程序时登录,然后直接进入formActivity 如果用户已经登录,则启动应用程序时必须出现活动屏幕,而不是登录屏幕 当用户在formActivity中填写表单时,他们将被引导到profileActivity 如果用户已经登录并填写了表单(在formActivity中),则在

我想在我的应用程序中创建3个活动。第一个是loginActivity,第二个是formActivity(包含用户填写的表单),第三个是ProfileActivity。我想按以下方式安排这些活动-

  • 用户需要在首次启动应用程序时登录,然后直接进入formActivity

  • 如果用户已经登录,则启动应用程序时必须出现活动屏幕,而不是登录屏幕

  • 当用户在formActivity中填写表单时,他们将被引导到profileActivity

  • 如果用户已经登录并填写了表单(在formActivity中),则在启动应用程序时,他们必须查看profileActivity


  • 请帮助我了解如何在闪屏中管理我活动的这些意图行为???

    我认为您可以在共享首选项中保存用户状态,并在闪屏活动中检查它。
    例如,“state”变量=1表示用户尚未登录,2表示用户未填写表单就登录,依此类推,共享首选项可能是检查用户是否已登录的好方法,您可以像这样使用它:

    SharedPreferences sp = this.getSharedPreferences( "login", Context.MODE_PRIVATE );
    sp.edit().putString( "idt", typ.getString( "id" ) ).apply();
    
    Intent it = new Intent( this, FormActivity.class );
    startActivity( it );
    finish();
    
    然后,在启动应用程序的地方,您可以检查是否存在共享首选项:

    SharedPreferences sp = getSharedPreferences( "login", MODE_PRIVATE );
        String Id = sp.getString( "idt", "" );=
        assert Id != null;
        if (!Id.equals( "" )) {
            startActivity( new Intent( this, TeacherDash.class ) );
            finish();
        }
    
    如果未登录,则将用户重定向到登录活动


    这同样适用于用户已填写表单,然后用户将被重定向到配置文件活动的情况。

    在我的应用程序中,用户需要先进行身份验证,然后才能开始使用该应用程序。我在startupActivity中有此代码

    access_token = sharedPrefidg.getString("access_token", "");
    if (!access_token.equalsIgnoreCase("")) {
       Intent i = new Intent(SplashScreen.this, MainActivity.class);
       i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
       startActivity(i);
       finish();
    }  else  {
      Intent i = new Intent(SplashScreen.this, Login.class);
      i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
      startActivity(i);
      finish();
    }