我正在使用Firebase作爲數據庫和批量推送通知的Android上創建應用程序。通常,當我的應用程序啓動時,它會轉到主頁面,一個登錄活動。活動驗證用戶是否使用仍處於登錄:Firebase註銷批量推送
Firebase dbRef = new Firebase(Constants.URL_DB);
AuthData auth = dbRef.getAuth();
if (auth != null) // Proceed with a logged in user
else // Show authentication layout
我的問題是,當我得到批量的通知,我點擊通知去應用程序,但隨後我沒有登錄爲我應該是... auth == null
。我不希望我的用戶在每次從批量推送時都需要登錄。我可以檢測到應用程序是從通知開始的嗎?我如何失去Firebase的身份驗證?
這裏是在MainActivity的OnCreate和的onResume:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initiating Batch
Batch.onStart(this);
// Initiating layout
setContentView(R.layout.login);
// Setting database
Firebase.setAndroidContext(this);
// Unrelated stuff done here (Setting Views, etc)
}
@Override
protected void onResume() {
super.onResume();
// Getting login information from previous authentication.
Firebase dbRef = new Firebase(Constants.URL_DB);
AuthData auth = dbRef.getAuth();
// I added the addAuthStateListener here
if (auth != null) {
goToHomePage();
}
}
嗯......聽起來很不尋常。你可以嘗試用偵聽器來檢測身份驗證:https://www.firebase.com/docs/android/guide/user-auth.html#section-monitoring-authentication它應該做同樣的事情,但我想知道,在狀態已知之前,以某種方式調用'getAuth()'。 –
這裏沒有足夠的代碼來猜測所有這些發生的時間。請參閱[請教](http://stackoverflow.com/help/how-to-ask)和[創建mcve](http://stackoverflow.com/help/mcve) – Kato
authData在'public void onAuthStateChanged(AuthData authData){...}'因爲我沒有登錄 – Sunshinator