顯示等待通知,直到回調從線程返回 (Show waiting notification till callback returns from thread)


問題描述

顯示等待通知,直到回調從線程返回 (Show waiting notification till callback returns from thread)

I am new to android and am stuck with this situation

I am calling a thread from the Activity UI. The thread will return to a callback function after doing some background operation .

Till then I need to show a waiting notification in the Activity UI.[Effectively freezing the app till the callback returns]

I tried with status flags and async task, but with partial success.

Please tell me the optimal solution to this problem.

‑‑‑‑‑

參考解法

方法 1:

Show A Progress before you start a thread and dismiss the progress dialog just before returning. 

For more about progress dialog see this link :http://developer.android.com/reference/android/app/ProgressDialog.html

方法 2:

You need to show the progress dialog box just before you start your thread.   

  private CustomizeDialog mCustomizeDialog = null;
  //in onCreate method
 mSubmitButton.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
   //checking few condition 
   mCustomizeDialog = new CustomizeDialog(makeRequestActivity.this);
   mCustomizeDialog.setTitle("Confirmation");
   mCustomizeDialog.setMessage("Make Request?");
    mCustomizeDialog.okButton.setOnClickListener(new OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mCustomizeDialog.dismiss();
                                show();
     });
mCustomizeDialog.show();
   private void show() {
                                mCustomizeDialog = new CustomizeDialog(makeRequestActivity.this);
                                mCustomizeDialog.setTitle("Requesting");
                                mCustomizeDialog.setMessage("Connecting...");
                                mCustomizeDialog.okButton.setVisibility(View.GONE);
                                mCustomizeDialog.cancelButton.setVisibility(View.GONE);
                                mCustomizeDialog.show();
                    }

and in my broadcast receiver

  private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
    public void onReceive(Context context, Intent intent) {
           if (intent.getAction().equals(request.CUSTOM_INTENT_MENU)) {
            mExtras = intent.getExtras();
            String result = mExtras.getString("tag");
            if (mCustomizeDialog.isShowing()) {
                mCustomizeDialog.dismiss();
            }
           }
};

(by osumPayalMRX)

參考文件

  1. Show waiting notification till callback returns from thread (CC BY‑SA 3.0/4.0)

#Callback #Android #multithreading #android-asynctask #android-activity






相關問題

將 C++ 函數指針設置為 C# 委託 (set C++ function pointer as C# delegate)

YouTube(注入)視頻結束回調 (YouTube (injected) video ends callback)

我如何在 Rails 中“驗證”銷毀 (How do I 'validate' on destroy in rails)

Як я магу рэалізаваць зваротныя выклікі на іншы сервер у C# (How can I implement callbacks to another server in c#)

顯示等待通知,直到回調從線程返回 (Show waiting notification till callback returns from thread)

應用程序未通過文本服務框架 DLL 檢測輸入語言更改 (Application not detecting input language changes via Text Service Framework DLL)

回調參數名稱 (Callback parameters name)

我是否以正確的方式考慮回調? (Am I thinking about Callbacks the right way?)

MSMQ 異步異常行為 - .NET 4.0 與 .NET 2.0 (MSMQ asynchronous exception behavior - .NET 4.0 vs .NET 2.0)

參數連接問題。我該如何處理 (parameter connection problem. How can I deal with this)

如何在 JavaScript 中實現動態回調參數 (How can I achieve dynamic callback arguments in JavaScript)

回調警告:回調錯誤創建破折號數據表 (Callback warning: Callback error creating dash' DataTable)







留言討論