简体   繁体   English

Android应用登录流程

[英]Android app login flow

How can I ask the user for login without flicker my MainActivity? 如何在不闪烁MainActivity的情况下要求用户登录?

I have two activities: LoginActivity and MainActivity. 我有两个活动:LoginActivity和MainActivity。 Let's start with my AndroidManifest.xml: 让我们从我的AndroidManifest.xml开始:

<activity 
    android:name=".app.MainActivity"
    android:logo="@drawable/logo_bw" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

The MainActivity is responsible to check if the user is logged in: MainActivity负责检查用户是否已登录:

@Override
protected void onResumeFragments() {
    super.onResumeFragments();
    if (isAuthenticated()) {
        showFragment(HOME, false);
    } else {
        startActivityForResult(new Intent(this, LoginActivity.class), LOGIN_REQUEST);
    }
}

This code flickers the MainActivity before showing the LoginActivity when the user is not logged in (eg. the first time using my app). 当用户未登录时(例如,第一次使用我的应用程序),此代码在显示LoginActivity之前会闪烁MainActivity。

I think I have two options to manage this: 我想我有两个选择来管理它:

1) transform LoginActivity into LoginFragment and let MainActivity show the correct fragment (as in this example from facebook ) 1)将LoginActivity转换为LoginFragment并让MainActivity显示正确的片段(如本例中的facebook

But I think fragments are miused at this facebook sample, because "A Fragment represents a behavior or a portion of user interface in an Activity." 但我认为片段在这个facebook样本中很有用,因为“片段代表了一个Activity中的行为或用户界面的一部分。” (see the documentation ) and the Login is not a portion of MainActivity user interface, has it's own lifecycle. (参见文档 )并且Login不是MainActivity用户界面的一部分,具有自己的生命周期。 Futhermore, I'm not considering login dialog. 此外,我不考虑登录对话。

2) create an "invisible" activity that redirects to the correct activity as suggested here 2)创建一个“隐形”活动,重定向到这里建议的正确活动

I didn`t understand what does "invisible activity" mean, because I tried out this solution and what happens is a flicker of the EntryActivity before showing the next activity. 我不明白“隐形活动”是什么意思,因为我尝试了这个解决方案,在发生下一个活动之前会发生什么变化是EntryActivity的闪烁。 And it all begins again... 这一切都重新开始......

I ended up doing the suggestion 2 from my question. 我最后从我的问题中做了建议2。 I created an EntryActivity with a blank layout that flickers quickly before showing the LoginActivity. 我创建了一个带有空白布局的EntryActivity,在显示LoginActivity之前会快速闪烁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM