簡體   English   中英

如何暫停一個活動,直到我在Android登錄時獲得Facebook ID?

[英]How to pause an Activity till I get facebook id while signing in in Android?

在Android中使用Facebook登錄/注冊時,Facebook發送請求需要一段時間。 因此,如何暫停活動(顯示進程對話框),直到我獲得嘗試注冊的用戶的facebook id / username? 我不能在基本監聽器中執行此操作,因為它是后台進程。

我嘗試使用AsyncTask,但我要么弄得怎么做,要么無法完成。 主要是前者。 我這樣做了:

  public class FacebookOperation extends AsyncTask<Void, Void, Void>
        {  





        @Override
        protected void onPreExecute()
        {  
            super.onPreExecute();



                mFacebook = new Facebook(APP_ID);
                mAsyncRunner = new AsyncFacebookRunner(mFacebook);
                reg = "facebook";
                SessionStore.restore(mFacebook, Register.this);
                SessionEvents.addAuthListener(new SampleAuthListener());
                //SessionEvents.addLogoutListener(new SampleLogoutListener());

        } 
        @Override 
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);

         }

        @Override 
        protected void onPostExecute(Void result)

        { 


               fillFormFb(); //Fills the form with the data from fb
        }

        @Override
        protected Void doInBackground(Void... params) {
            mLoginButton.init(Register.this, mFacebook,permissions);


            return null;
        }

          }

使用AsyncTask在后台運行您的進程..您可以在加載操作時顯示進度條。

public class FacebookOperation extends AsyncTask<Void, Void, Void>
{  
@Override
protected void onPreExecute()
{  
    super.onPreExecute();
    dialog.setMessage("Please wait...");
    dialog.setCancelable(false);
    dialog.show();

} 
@Override 
protected void onProgressUpdate(Void... values) {
    super.onProgressUpdate(values);
    // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
 }

@Override 
protected void onPostExecute(Void result)

{ 
      //Post Execute
       dialog.cancel();
}
@Override
protected Void doInBackground(Void... params) {

  // Your operation..Dont Edit Any Views here

    return null;
}

}

編輯

我想你可以按照這個鏈接將facebook與你的應用程序集成。 它會對你有所幫助。

希望能幫助到你

暫無
暫無

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

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