0
我在我的應用程序中使用Facebook SDK。我的要求是爲不同的用戶維護Facebook會話。我有在sqlite數據庫中的所有用戶名。我使用下面的代碼來檢查用戶是否已經登錄Facebook。如果是第一次,我顯示Facebook對話框並獲取訪問令牌,並將其存儲在數據庫中以供特定用戶使用,同時也使該用戶的會話無效。第二位用戶嘗試登錄Facebook時會發生問題。當登錄對話框出現時,它顯示log cat中的泄漏窗口錯誤。Android中的Facebook對話框中的泄露窗口
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)