<tfoot id='F4uSn'></tfoot>
    <i id='F4uSn'><tr id='F4uSn'><dt id='F4uSn'><q id='F4uSn'><span id='F4uSn'><b id='F4uSn'><form id='F4uSn'><ins id='F4uSn'></ins><ul id='F4uSn'></ul><sub id='F4uSn'></sub></form><legend id='F4uSn'></legend><bdo id='F4uSn'><pre id='F4uSn'><center id='F4uSn'></center></pre></bdo></b><th id='F4uSn'></th></span></q></dt></tr></i><div id='F4uSn'><tfoot id='F4uSn'></tfoot><dl id='F4uSn'><fieldset id='F4uSn'></fieldset></dl></div>
    <legend id='F4uSn'><style id='F4uSn'><dir id='F4uSn'><q id='F4uSn'></q></dir></style></legend>

        <bdo id='F4uSn'></bdo><ul id='F4uSn'></ul>

      <small id='F4uSn'></small><noframes id='F4uSn'>

      1. Android 后退按钮和进度对话框

        时间:2023-08-28

        <small id='QSSFN'></small><noframes id='QSSFN'>

        <i id='QSSFN'><tr id='QSSFN'><dt id='QSSFN'><q id='QSSFN'><span id='QSSFN'><b id='QSSFN'><form id='QSSFN'><ins id='QSSFN'></ins><ul id='QSSFN'></ul><sub id='QSSFN'></sub></form><legend id='QSSFN'></legend><bdo id='QSSFN'><pre id='QSSFN'><center id='QSSFN'></center></pre></bdo></b><th id='QSSFN'></th></span></q></dt></tr></i><div id='QSSFN'><tfoot id='QSSFN'></tfoot><dl id='QSSFN'><fieldset id='QSSFN'></fieldset></dl></div>

        <tfoot id='QSSFN'></tfoot>
          <tbody id='QSSFN'></tbody>
              • <bdo id='QSSFN'></bdo><ul id='QSSFN'></ul>
                <legend id='QSSFN'><style id='QSSFN'><dir id='QSSFN'><q id='QSSFN'></q></dir></style></legend>

                  本文介绍了Android 后退按钮和进度对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 AsyncTask,它在工作时显示一个 progressDialog(它从 doInBackground 中调用 runOnUiThread 来显示进度对话框).

                  I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUiThread from within doInBackground to show the progress dialog).

                  在运行时,我想允许使用后退按钮取消操作;其他人遇到了这个问题:返回按钮不起作用,而progressDialog 正在运行

                  Whilst its running I want to allow the use of the back button to cancel the operation; someone else has had this problem: BACK Button is not working ,while progressDialog is running

                  由于什么原因我无法回复该主题,因此不得不开始另一个?!(另一天的另一个问题)

                  For what ever reason I can't reply to that thread, hence having to start another?! (Another question for another day)

                  我和 Sandy 有同样的想法,但是当 progressDialog 显示时,这段代码从未被调用,这是为什么呢?我已经在我的主要活动类中实现了它,progressDialog 是否暂时将前台焦点从我的类中移开?

                  I had the same idea as Sandy but this code is never called whilst the progressDialog is showing, why is this? I have implemented it inside my main activity class, does the progressDialog take the foreground focus away from my class temporarily?

                  推荐答案

                  首先,您应该从 OnPreExecute 显示您的对话框,将其隐藏在 OnPostExecute 中,并且 - 如有必要- 通过发布进度修改它.(参见这里)

                  First, you should show your dialog from OnPreExecute, hide it in OnPostExecute, and - if necessary - modify it by publishing progress. (see here)

                  现在回答您的问题:ProgressDialog.show() 可以将 OnCancelListener 作为参数.您应该提供一个在进度对话框实例上调用 cancel() 的方法.

                  Now to your question: ProgressDialog.show() can take a OnCancelListener as an argument. You should provide one that calls cancel() on the progress dialog instance.

                  示例:

                      @Override
                      protected void onPreExecute(){
                          _progressDialog = ProgressDialog.show(
                                  YourActivity.this,
                                  "Title",
                                  "Message",
                                  true,
                                  true,
                                  new DialogInterface.OnCancelListener(){
                                      @Override
                                      public void onCancel(DialogInterface dialog) {
                                          YourTask.this.cancel(true);
                                          finish();
                                      }
                                  }
                          );
                      }
                  

                  其中 _progressDialogYourTaskProgressDialog 成员.

                  where _progressDialog is a ProgressDialog member of YourTask.

                  此类在 API 级别 26 中已弃用.ProgressDialog 是一种模式对话框,它会阻止用户与应用程序交互.反而使用此类,您应该使用进度指示器,例如ProgressBar,可以嵌入到应用程序的 UI 中.或者,您可以使用通知来通知用户任务的进度.链接

                  This class was deprecated in API level 26. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress. LINK

                  这篇关于Android 后退按钮和进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:带有 OK 和 Cancel 的 Swift 警报视图:点击了哪个按钮 下一篇:如何实现材料指南中描述的全屏对话框?

                  相关文章

                  最新文章

                    1. <small id='vQV8I'></small><noframes id='vQV8I'>

                    2. <tfoot id='vQV8I'></tfoot>

                      <i id='vQV8I'><tr id='vQV8I'><dt id='vQV8I'><q id='vQV8I'><span id='vQV8I'><b id='vQV8I'><form id='vQV8I'><ins id='vQV8I'></ins><ul id='vQV8I'></ul><sub id='vQV8I'></sub></form><legend id='vQV8I'></legend><bdo id='vQV8I'><pre id='vQV8I'><center id='vQV8I'></center></pre></bdo></b><th id='vQV8I'></th></span></q></dt></tr></i><div id='vQV8I'><tfoot id='vQV8I'></tfoot><dl id='vQV8I'><fieldset id='vQV8I'></fieldset></dl></div>
                      • <bdo id='vQV8I'></bdo><ul id='vQV8I'></ul>
                    3. <legend id='vQV8I'><style id='vQV8I'><dir id='vQV8I'><q id='vQV8I'></q></dir></style></legend>