织物套件的延迟初始化? [英] Lazy initialization of Fabric kits?

查看:78
本文介绍了织物套件的延迟初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以延迟初始化Fabric Kit?例如,现在我要做:

Is it possible to lazily initialize Fabric Kits? for example, right now I do:

Fabric.with(this, crashlytics, twitterCore, tweetUi); // 500ms

我只想初始化Crashlytics(没有Twitter内容),如下所示,因为它速度提高了10倍,而且我不需要立即使用Twitter。

I would like to initialize only Crashlytics (no twitter stuff), like below, because it is 10x faster, and I don't need the Twitter stuff right away

Fabric.with(this, crashlytics); // 50ms

稍后,当用户访问我需要TwitterCore&的活动时TweetUi,我想在使用它们之前将它们添加到Fabric中。

Later on, when the user visits an activity where I need TwitterCore & TweetUi, I'd like to add them to Fabric on the fly before using them.

这可能吗?

编辑: 我设法做到了反思,这显然不理想,但暂时可行。我仍在寻找适当的解决方案。这是我的操作方法:

    try {
        final Fabric newFabric = (new Fabric.Builder(context)).kits(crashlytics, twitterCore, tweetUi).build();
        final Method method = Fabric.class.getDeclaredMethod("setFabric", Fabric.class);
        method.setAccessible(true);
        method.invoke(null, newFabric);
    } catch (Exception e) {
        Timber.e(e, e.getMessage());
    }


推荐答案

Fabric的Mike。当前,我们仅尊重Fabric的首次初始化。一种选择是先初始化所有内容,或者如果您可以错过一些崩溃,则不要初始化Twitter和Crashlytics,直到稍后在应用程序代码中初始化。

Mike from Fabric here. Currently, we only respect the first initialization of Fabric. One option would to be initialize everything up front or if you're ok for missing some crashes, not initialize Twitter and Crashlytics until later in your app's code.

这篇关于织物套件的延迟初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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