我们一直在使用Firebase供用户登录。根据我们的清单,主要启动器是我们的登录活动。启动时,它会检查用户是否已连接。如果是,则启动另一个活动,否则它将保留在登录页面上。
问题:当我们启动应用程序并且我们已连接时,我们可以看到某种双重活动打开动画,因为登录页面打开,半秒后主活动开始。
如何解决这个问题?
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ultramirinc.champs_mood">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".RegisterActivity"
android:label="@string/title_activity_register"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"/>
<activity
android:name=".ScheduleAdder"
android:label="@string/title_activity_schedule_adder"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps"
android:screenOrientation="portrait"/>
<activity
android:name=".TabActivity"
android:label="@string/title_activity_tab"
android:theme="@style/AppTheme"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".SettingsActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".NotificationObject"
android:screenOrientation="portrait"/>
<activity
android:name=".FriendProfilActivity"
android:screenOrientation="portrait"/>
</application>
登录:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
firebaseAuth = FirebaseAuth.getInstance();
//getting firebase auth object
//if the objects getcurrentuser method is not null
//means user is already logged in
if(firebaseAuth.getCurrentUser() != null) {
Log.d("Login debug", "current user: " + firebaseAuth.getCurrentUser().toString());
//close this activity
UserManager.getInstance().getUserInformations();
finish();
Intent intent = new Intent(this, TabActivity.class);
startActivity(intent);
}
setContentView(R.layout.activity_login);
//Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
//toolbar.setTitle("Champlain mood");
//setSupportActionBar(toolbar);
Intent intent = getIntent();
// Set up the login form.
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
populateAutoComplete();
mPasswordView = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == R.id.login_text || id == EditorInfo.IME_NULL) {
attemptLogin();
return true;
}
return false;
}
});
progressDialog = new ProgressDialog(this);
Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
mLoginFormView = findViewById(R.id.login_form);
//mProgressView = findViewById(R.id.login_progress);
}