簡體   English   中英

Android-登錄后會不斷彈出Facebook登錄對話框和進度指示

[英]Android - Facebook login dialog and progress indicatior keeps popping out upon logging in

我已經在運行Android應用程序中實現了Facebook功能。 當用戶按下Facebook ImageButton ,它將啟動身份驗證過程(SSO)。 然后在用戶的facebook牆上發布信息。 一切都在模擬器上順利運行。 能夠張貼在牆上並能夠查看。

但是,在實際設備上進行測試時,用戶按下ImageButton之后會出現一個問題。 ProgressDialog會不斷彈出,並且不會停止。 用戶將需要通過按設備上的“ Home按鈕來關閉程序。

在此處輸入圖片說明

可能是什么問題呢? 我沒有在Facebook.java類中更改任何代碼

Adapter.java

ImageButton fbBtn = (ImageButton) view.findViewById(R.id.fb); 
    fbBtn.setOnClickListener(
            new Button.OnClickListener() {
                public void onClick(View v) 
                {
                    taskListener.doAuthentication();
                    taskListener.postToWall(data[position], text[position], name[position]); 
                    System.out.println(text[position]);
                    }
                }

        );

public static interface FBookTaskListener{
    public void doAuthentication();
    public void postToWall(String data, String text, String name);
}

Activity.java

protected class TheTask extends AsyncTask<Void, Void, MyResultClass >{

    protected void onPreExecute() {
        dialog = ProgressDialog.show(Activity.this, "Retrieving Information", "Please wait for a few seconds...", true, false);
        dialog.setCancelable(true);
    }

    protected MyResultClass doInBackground(Void... params) {
        searchContent();
        MyResultClass result = new MyResultClass();
        result.mStrings = mStrings;
        result.dStrings = dStrings;
        result.date = date;
        result.name = name;
        return result;
    }   
    @Override
    protected void onPostExecute(MyResultClass result) {            
        dStrings = result.dStrings;
        mStrings = result.mStrings;
        date = result.date;
        name = result.name;
        LazyAdapter adapter = new Adapter(Activity.this, mStrings, dStrings, name);
        list.setAdapter(adapter);

        adapter.setTaskListener(new FBookTaskListener(){
            public void doAuthentication()
            {
                    // here all your FB authentication related stuff.

                mPrefs = getPreferences(MODE_PRIVATE);
                String access_token = mPrefs.getString("access_token", null);
                long expires = mPrefs.getLong("access_expires", 0);
                if(access_token != null) {
                    facebook.setAccessToken(access_token);
                }
                if(expires != 0) {
                    facebook.setAccessExpires(expires);
                }

                /*
                 * Only call authorize if the access_token has expired.
                 */
                if(!facebook.isSessionValid()) {

                facebook.authorize(Activity.this, new String[] {"publish_stream", "offline_access", "read_stream"}, new DialogListener() {
                    @Override
                    public void onComplete(Bundle values) 
                    {
                        SharedPreferences.Editor editor = mPrefs.edit();
                        editor.putString("access_token", facebook.getAccessToken());
                        editor.putLong("access_expires", facebook.getAccessExpires());
                        editor.commit();
                    }

                    @Override
                    public void onFacebookError(FacebookError e) {
                        Log.d("FACEBOOK ERROR","FB ERROR. MSG: "+e.getMessage()+", CAUSE: "+e.getCause());
                    }

                    @Override
                    public void onError(DialogError e) {
                        Log.e("ERROR","AUTH ERROR. MSG: "+e.getMessage()+", CAUSE: "+e.getCause());
                    }

                    @Override
                    public void onCancel() {
                        Log.d("CANCELLED","AUTH CANCELLED");
                    }
                });
            }

            }

            @Override
            public void postToWall(String data, String text, String name) {
                postToFacebook(data, text, name);

            }

        });

        dialog.dismiss();
    }       
}

在您的活動中添加此代碼

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    facebook.authorizeCallback(requestCode, resultCode, data);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM