How can I ask the user for login without flicker my MainActivity?
I have two activities: LoginActivity and MainActivity. Let's start with my 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:
@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).
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 )
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." (see the documentation ) and the Login is not a portion of MainActivity user interface, has it's own lifecycle. Futhermore, I'm not considering login dialog.
2) create an "invisible" activity that redirects to the correct activity as suggested here
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. And it all begins again...
I ended up doing the suggestion 2 from my question. I created an EntryActivity with a blank layout that flickers quickly before showing the LoginActivity.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.