2

我用来com.facebook.widget.UserSettingsFragment在我的应用程序中管理登录/注销到 Facebook:

UserSettingsFragment userSettingsFragment = new UserSettingsFragment();
Session session = Session.getActiveSession();
if(session==null || session.isClosed()){
    userSettingsFragment.setPublishPermissions(Arrays.asList("publish_actions"));
}
fragmentTransaction.replace(R.id.content_container, userSettingsFragment, "userSettingsFragment");

它似乎可以正确登录/注销,但是当我Fragment已经登录并暂停它(通过替换Fragment例如)时启动它时,它会崩溃。似乎它有一些线程正在运行,当它完成时,它需要它Activity并且它不再存在,所以它崩溃了。

对我来说它看起来像一个错误,还是我错过了什么?

08-18 12:16:58.345: E/AndroidRuntime(18068): java.lang.IllegalStateException: Fragment UserSettingsFragment{420c3a08} not attached to Activity
08-18 12:16:58.345: E/AndroidRuntime(18068):    at android.support.v4.app.Fragment.getResources(Fragment.java:579)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at com.facebook.widget.UserSettingsFragment.processImageResponse(UserSettingsFragment.java:383)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at com.facebook.widget.UserSettingsFragment.access$7(UserSettingsFragment.java:379)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at com.facebook.widget.UserSettingsFragment$2.onCompleted(UserSettingsFragment.java:370)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at com.facebook.widget.ImageDownloader$1.run(ImageDownloader.java:161)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at android.os.Handler.handleCallback(Handler.java:730)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at android.os.Looper.loop(Looper.java:137)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at android.app.ActivityThread.main(ActivityThread.java:5103)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at java.lang.reflect.Method.invokeNative(Native Method)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at java.lang.reflect.Method.invoke(Method.java:525)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-18 12:16:58.345: E/AndroidRuntime(18068):    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

2

我见过类似的行为。如果我在登录后关闭 UserSettingsFragment,但在图像更新之前,我会收到无活动附加崩溃。

我正在使用以下解决方法。在 UserSettingsFragment.java 中,我修改了 processImageResponse(String id, ImageResponse response) 以检查是否添加了片段:

    private void processImageResponse(String id, ImageResponse response) {
    if (response != null && UserSettingsFragment.this.isAdded()) {
        Bitmap bitmap = response.getBitmap();
        if (bitmap != null) {
            BitmapDrawable drawable = new BitmapDrawable(UserSettingsFragment.this.getResources(), bitmap);
            drawable.setBounds(0, 0,
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_height));
            userProfilePic = drawable;
            userProfilePicID = id;
            connectedStateLabel.setCompoundDrawables(null, drawable, null, null);
            connectedStateLabel.setTag(response.getRequest().getImageUri());
        }
    }
}

直接更新 SDK 显然不理想,但也不会让我的应用崩溃:-)

于 2014-07-30T22:50:07.400 回答
2

确实,它看起来像一个错误。这是我的错误报告

于 2013-08-22T06:05:45.903 回答