如何与在用户beeing在previous运行记录与火力地堡一个应用程序的冷启动处理 [英] How deal with cold start of an app where user has beeing logged with Firebase at previous run

查看:197
本文介绍了如何与在用户beeing在previous运行记录与火力地堡一个应用程序的冷启动处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢到火力地堡用户可以与G +,Facebook或Twitter的帮助下登录。当他们被记录,一切都很好。

Thank to Firebase the user can logged with the help of G+, Facebook or Twitter. When they are logged, everything is fine.

在Android应用程序被关闭并重新打开,如何重新启用previous成功登录的用户与火力地堡API。它不无论是在应用程序演示或文档中解释。

When the Android app is closed and re-opened, how to reenable the previous succeed logged user with the Firebase API. It is not explained neither in the app demo or in the documentation.

有关为例对于Facebook,该SDK似乎保存的道理,这就是为什么按钮处于连接状态(表明你可以断开)。但对于火力地堡和其他认证系统。

For exemple for Facebook, the sdk seems to save the token, that 's why the button is at connected state (showing that you can disconnect). But what about Firebase and for other authentication systems.

推荐答案

感谢@弗兰克面包车-Puffelen的答​​案,我有一些试验,直到我得到有关的东西(至少对我来说:评论,欢迎来改善)。

Thanks to the @Frank-van-Puffelen answer, I had some trials until I get something relevant (at least for me : comment are welcome to improve).

我已经根据我的OAuth的架构分为3个主成分:
fdsfds

I have based my OAuth architecture into 3 mains components : fdsfds


  1. 位于应用中的一个单一的AuthStateListener。

  2. 一个utils的辛格尔顿OAuthManager与所有身份验证过程
  3. 处理
  4. 一个或与身份认证的用户交互涉及许多活动(签到按钮等)

应用程序类

FacebookSdk.sdkInitialize(this);

Firebase.setAndroidContext(this);
Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);
Firebase.getDefaultConfig().setPersistenceEnabled(true);

Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.addAuthStateListener(new Firebase.AuthStateListener() {
    @Override
    public void onAuthStateChanged(AuthData authData) {
        if (authData != null) {
            // user is logged in
            // create a partialUser from authData
            OAuthManager.getDefault().setAuthenticatedUser(authData);
            // fetch, merge and save back the partialUser with server registerUser.
            OAuthManager.getDefault().startFetchingUserInfo();
        } else {
            // user is not logged in
            // Try to retrieve the user from Facebook SDK             
            // Try to retrieve the user from "Token and Id save in Android Preferences (in case of issue, or cache reset from Firebase))
            // In retrieve is not possible, clean auth data 
            OAuthManager.getDefault().retrieveOAuth(MilleZimU.getInstance());
        }
    }
});

OAuthManager

下面是每一个处理身份验证(部分已经从火力地堡专用演示活动副本)

Here is every services that deal with authentication (part has been copy from the Firebase dedicated demo activity)

SignInActivity

下面仅停留,与用户界面交互处理的部分。

Here only remain the part that deal with UI interaction.

Retreiving?

我不知道这是必要的,但个别情况(可能是由于崩溃或应用程序的更新),认证状态从哪里不同火力地堡| preFS | FacebookSdk。我会看到随着时间的推移。

I'm not sure this is necessary, but case to case (maybe due to crash or update of the app), authentication status where different from Firebase|Prefs|FacebookSdk. I will see with time.

这篇关于如何与在用户beeing在previous运行记录与火力地堡一个应用程序的冷启动处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆