我用来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)