0

我在我的应用程序中使用 Facebook SDK。我的要求是为不同的用户维护 Facebook 会话。我在 sqlite 数据库中拥有所有用户名。我使用以下代码检查用户是否已经登录 Facebook。如果是第一次,我会显示 Facebook 对话框并获取访问令牌,并为特定用户存储在 db 中,并使该用户的会话无效。当第二个用户尝试登录 Facebook 时,就会出现问题。当登录对话框出现时,它在 log cat 中显示泄漏窗口错误。

db = Stats.this.openOrCreateDatabase(DB_NAME,
                    MODE_PRIVATE, null);

            Cursor cur = db.rawQuery("SELECT * FROM " + USER_TABLE_NAME, null);
            if (cur != null) {
                if (cur.moveToFirst()) {
                    do {
                        String reader_name = cur.getString(cur
                                .getColumnIndex("username"));
                        Log.v("reader_name", reader_name);
                        if (reader_name.equals(reader_name_db)) {
                            if (cur.getString(cur.getColumnIndex("fb_token"))
                                    .equals("0")) {
                                authenticatedFacebook.authorize(Stats.this,
                                        PERMISSIONS, -1,
                                        new TestLoginListener());

                            } else {
                                accesstoken = cur.getString(cur
                                        .getColumnIndex("fb_token"));
                                Log.v("AccessToken", accesstoken);
                            }
                        }

                    } while (cur.moveToNext());
                }
            }
            cur.close();
            db.close();

            if (!accesstoken.equals("0")) {
                Toast.makeText(Stats.this, "Access token already present",
                        Toast.LENGTH_LONG).show();
                shareThroughFB();
            }

public class TestLoginListener implements DialogListener {

        public void onComplete(Bundle values) {
            // TODO Auto-generated method stub
            if (authenticatedFacebook.isSessionValid()) {
                accesstoken = authenticatedFacebook.getAccessToken();
                Log.v("AccessToken", accesstoken);
                db = Stats.this.openOrCreateDatabase(REDOMETER_DB_NAME,
                        MODE_PRIVATE, null);

                db.execSQL("update " + USER_TABLE_NAME + " set fb_token='"
                        + accesstoken + "' where username='" + reader_name_db
                        + "'");
                db.close();

    FbDialog.mSpinner.dismiss();
                fb_Logout();


                shareThroughFB();

            }
        }

        public void onFacebookError(FacebookError e) {
            // TODO Auto-generated method stub

        }

        public void onError(DialogError e) {
            // TODO Auto-generated method stub

        }

        public void onCancel() {
            // TODO Auto-generated method stub

        }

    }

它显示以下错误。

 10-29 08:41:55.500: E/WindowManager(16738): Activity com.readometer.ReadometerTab has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42b4e270 V.E..... R.....I. 0,0-1080,1920} that was originally added here
10-29 08:41:55.500: E/WindowManager(16738): android.view.WindowLeaked: Activity com.readometer.ReadometerTab has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42b4e270 V.E..... R.....I. 0,0-1080,1920} that was originally added here
10-29 08:41:55.500: E/WindowManager(16738):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:426)
10-29 08:41:55.500: E/WindowManager(16738):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:235)
10-29 08:41:55.500: E/WindowManager(16738):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-29 08:41:55.500: E/WindowManager(16738):     at android.app.Dialog.show(Dialog.java:282)
10-29 08:41:55.500: E/WindowManager(16738):     at com.facebook.android.Facebook.dialog(Facebook.java:628)
10-29 08:41:55.500: E/WindowManager(16738):     at com.facebook.android.Facebook.startDialogAuth(Facebook.java:297)
10-29 08:41:55.500: E/WindowManager(16738):     at com.facebook.android.Facebook.authorize(Facebook.java:195)
10-29 08:41:55.500: E/WindowManager(16738):     at com.readometer.Stats.onClick(Stats.java:596)
10-29 08:41:55.500: E/WindowManager(16738):     at android.view.View.performClick(View.java:4354)
10-29 08:41:55.500: E/WindowManager(16738):     at android.view.View$PerformClick.run(View.java:17961)
10-29 08:41:55.500: E/WindowManager(16738):     at android.os.Handler.handleCallback(Handler.java:725)
10-29 08:41:55.500: E/WindowManager(16738):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-29 08:41:55.500: E/WindowManager(16738):     at android.os.Looper.loop(Looper.java:137)
10-29 08:41:55.500: E/WindowManager(16738):     at android.app.ActivityThread.main(ActivityThread.java:5328)
10-29 08:41:55.500: E/WindowManager(16738):     at java.lang.reflect.Method.invokeNative(Native Method)
10-29 08:41:55.500: E/WindowManager(16738):     at java.lang.reflect.Method.invoke(Method.java:511)
10-29 08:41:55.500: E/WindowManager(16738):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
10-29 08:41:55.500: E/WindowManager(16738):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
10-29 08:41:55.500: E/WindowManager(16738):     at dalvik.system.NativeStart.main(Native Method)
10-29 08:41:55.510: E/WindowManager(16738): Activity com.readometer.ReadometerTab has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42b592d8 V.E..... R.....ID 0,0-502,346} that was originally added here
10-29 08:41:55.510: E/WindowManager(16738): android.view.WindowLeaked: Activity com.readometer.ReadometerTab has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42b592d8 V.E..... R.....ID 0,0-502,346} that was originally added here
10-29 08:41:55.510: E/WindowManager(16738):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:426)
10-29 08:41:55.510: E/WindowManager(16738):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:235)
10-29 08:41:55.510: E/WindowManager(16738):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-29 08:41:55.510: E/WindowManager(16738):     at android.app.Dialog.show(Dialog.java:282)
10-29 08:41:55.510: E/WindowManager(16738):     at com.facebook.android.FbDialog$FbWebViewClient.onPageStarted(FbDialog.java:197)
10-29 08:41:55.510: E/WindowManager(16738):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:399)
10-29 08:41:55.510: E/WindowManager(16738):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 08:41:55.510: E/WindowManager(16738):     at android.os.Looper.loop(Looper.java:137)
10-29 08:41:55.510: E/WindowManager(16738):     at android.app.ActivityThread.main(ActivityThread.java:5328)
10-29 08:41:55.510: E/WindowManager(16738):     at java.lang.reflect.Method.invokeNative(Native Method)
10-29 08:41:55.510: E/WindowManager(16738):     at java.lang.reflect.Method.invoke(Method.java:511)
10-29 08:41:55.510: E/WindowManager(16738):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
10-29 08:41:55.510: E/WindowManager(16738):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
10-29 08:41:55.510: E/WindowManager(16738):     at dalvik.system.NativeStart.main(Native Method)
10-29 08:41:56.090: I/GATE(16738): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
10-29 08:41:56.090: D/AndroidRuntime(16738): Shutting down VM
10-29 08:41:56.095: W/dalvikvm(16738): threadid=1: thread exiting with uncaught exception (group=0x413a1930)
10-29 08:41:56.100: E/AndroidRuntime(16738): FATAL EXCEPTION: main
10-29 08:41:56.100: E/AndroidRuntime(16738): java.lang.IllegalArgumentException: View not attached to window manager
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:402)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:304)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.app.Dialog.dismissDialog(Dialog.java:325)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.app.Dialog.dismiss(Dialog.java:307)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at com.facebook.android.FbDialog$FbWebViewClient.onPageFinished(FbDialog.java:203)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:408)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.os.Looper.loop(Looper.java:137)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at android.app.ActivityThread.main(ActivityThread.java:5328)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at java.lang.reflect.Method.invokeNative(Native Method)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at java.lang.reflect.Method.invoke(Method.java:511)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
10-29 08:41:56.100: E/AndroidRuntime(16738):    at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

0

删除此行

FbDialog.mSpinner.dismiss();

如果对话框没有消失,请将其放入 try/catch 中:

try{
     FbDialog.mSpinner.dismiss(); 
 } catch(Exception e ) 
 { e.printStackTrace(); }

并发布您的堆栈跟踪;)

于 2013-10-29T12:13:29.523 回答