经过漫长的空闲时间Android应用程序重新初始化Twitter Fabric

时间:2015-07-09 23:21:07

标签: android android-fragments twitter twitter-fabric

所以我的Android应用程序有以下组件:一个LoginActivity,一个使用导航抽屉的MainActivity,一组由主要活动中的Nav抽屉处理的各种片段。

在LoginActivity中,我设置了TwitterAuthConfig并将其提供给Fabric.with(.... Twitter(authConfig)...),基本上按照他们在文档中所做的做法:Fabric integration documentation < / p>

用户浏览LoginActivity并成功登录后,进入主活动,打开导航抽屉并让他们选择他们想要去的片段。启动MainActivity后,LoginActivity调用 this.finish()

我的问题是我使用的片段之一使用嵌入式Twitter时间线,需要通过Fabric.with()调用进行Fabric身份验证。这是第一次精细,但是一旦我离开应用程序并且它在后台停留了一段时间,我相信onDestroy()被调用,然后Fabric实例被删除。

因此,当我从后台再次打开它时,会出现以下错误:

07-09 15:59:55.179    7933-7933/com.writers.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.writers.myapp, PID: 7933
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.writers.myapp/com.writers.myapp.MainActivity}: java.lang.IllegalStateException: Must Initialize Fabric before using singleton()
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2329)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
        at android.app.ActivityThread.access$900(ActivityThread.java:147)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
 Caused by: java.lang.IllegalStateException: Must Initialize Fabric before using singleton()
        at io.fabric.sdk.android.Fabric.singleton(Fabric.java:265)
        at io.fabric.sdk.android.Fabric.getKit(Fabric.java:516)
        at com.twitter.sdk.android.tweetui.TweetUi.checkInitialized(TweetUi.java:120)
        at com.twitter.sdk.android.tweetui.TweetUi.getInstance(TweetUi.java:69)
        at com.twitter.sdk.android.tweetui.TwitterListTimeline$Builder.<init>(TwitterListTimeline.java:108)
        at com.myapp.newstimeline.TimelineFragment.onCreateView(TimelineFragment.java:49)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1120)
        at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1929)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
        at android.app.Activity.performStart(Activity.java:5949)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
        at android.app.ActivityThread.access$900(ActivityThread.java:147)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
07-09 15:59:55.203     775-1192/? W/ActivityManager﹕ Force finishing activity com.writers.myapp/.MainActivity

知道如何解决这个问题吗?

  • 我应该在MainActivity中添加额外的Fabric.with()语句吗?
  • 我应该捕获IllegalStateException吗?如果是这样,在哪里?
  • 我这样做错了吗?

提前感谢您的帮助!

0 个答案:

没有答案