1

这是 Facebook 本身提供的基本程序 - 将 android 应用程序连接到 facebook:但我似乎得到了一个错误:

Activity com.Facebook.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow@DecorView@40512630 that was originally added here:

尝试了以下事情:

  • 我已经验证了我的keyHash.
  • 我已经验证了我的Android.xml
  • 我在论坛上寻找更多的输入。

有什么建议么 ???

主要活动:

package com.example.facebookconnectionapp;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.i("Facebook Activity", "Before opening session");

        Session.openActiveSession(this, true, new Session.StatusCallback() {

            @Override
            public void call(Session session, SessionState state, Exception exception) {
                // TODO Auto-generated method stub

                Log.i("Facebook Activity", "Checking if session open");

                if(session.isOpened()){

                    Log.i("Facebook Activity", "Session is open");
                    Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                        @Override
                        public void onCompleted(GraphUser user, Response response) {
                            // TODO Auto-generated method stub

                            Log.i("Facebook Activity", "Inside GraphCallback");

                            TextView textView = (TextView) findViewById(R.id.textView1);
                            textView.setText(user.getUsername());
                        }
                    });
                } else {

                    Log.i("Facebook Activity", "Session not open");
                }

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
    }

}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.facebookconnectionapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.facebookconnectionapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
        <activity android:name="com.facebook.LoginActivity"></activity>
    </application>

</manifest>
4

2 回答 2

4

确保您已连接到互联网。如果不是,您将收到此错误。

于 2013-09-21T04:46:18.677 回答
3

leaked window表示您Activity已关闭(已完成)并且还有任何其他Dialog(进度/警报)仍处于打开状态。

dismissDialog调用finish()或捕获之前一定要s,Exception这样Activity它就不会被关闭。

key hash它与和无关Manifest.xml

于 2013-07-15T06:09:37.800 回答