【问题标题】:Progress Dialog spins forever on Activity Resume进度对话框在 Activity Resume 上永远旋转
【发布时间】:2012-06-15 02:17:38
【问题描述】:

我正在使用 Handler 调用 WebServices 并在

的帮助下显示 ProgressBar
// Create Progress dialogs
    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case mDialogProgress:
            dataLoadProgress = new ProgressDialog(this);
            dataLoadProgress.setMessage("Loading...");
            dataLoadProgress.setIndeterminate(true);
            dataLoadProgress.setCancelable(false);
            dataLoadProgress
                    .setProgressStyle(android.R.attr.progressBarStyleSmallTitle);
            return dataLoadProgress;
        default:
            return null;
        }
    }

我已经在调用下面的方法 onStop 来停止它的显示。

        @Override
        public void onStop() {
            if (dataLoadProgress != null && dataLoadProgress.isShowing())
                stopThread();
            super.onStop();
        }

        private synchronized void stopThread() {
        try {
            if (getServerData != null) {
                if (dataLoadProgress != null && dataLoadProgress.isShowing())
                    dismissDialog(mDialogProgress);
                getServerData = null;
                // // mHandler = null;
            }
        } catch (Exception e) {
            CommonFunctions.DoCatchOperation(e);
        }
        }

现在,当我的应用程序进入后台模式并恢复时,它会显示进度对话框并永远旋转,我无法使用后退按钮作为它的 setCancelable(false);

来停止它

我尝试在 onResume() 中调用我的 stopThread() ,如果显示进度,那么它将停止,但我在 onCreate 中调用 webservice 并且它开始显示 ProgressDialog 并在 onCreate onResume 被调用并且我的 ProgressDialog 被关闭后的下一个实例。

所以我想在后台永远停止这种旋转。

【问题讨论】:

  • 天哪。你实现了这个线程机制。为什么?你可以试试 AsyncTask 。你是这样显示对话框的吗?
  • @PareshMayani 我现在有 32 个活动,我正在处理已实现的代码。所以如果可能的话,请先尝试修复现有代码。
  • 32 活动然后呢?你不能定义 Super AsyncTask 类并在所有这 32 个活动中扩展它吗?您只需在超级基础任务中编写对话框显示即可。
  • @PareshMayani 好的.. 没关系.. 但是您知道为什么要恢复对话吗?因为它在 onPause/onStop 之前已经被解散,甚至不再显示它。

标签: android android-activity android-dialog android-lifecycle android-progressbar


【解决方案1】:

我在这里只添加了一行条件。
if(dataLoadProgress == null) 它对我有用。

// Create Progress dialogs
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case mDialogProgress:
        if(dataLoadProgress == null)
            dataLoadProgress = new ProgressDialog(this);
        dataLoadProgress.setMessage("Loading...");
        dataLoadProgress.setIndeterminate(true);
        dataLoadProgress.setCancelable(false);
        dataLoadProgress
                .setProgressStyle(android.R.attr.progressBarStyleSmallTitle);
        return dataLoadProgress;
    default:
        return null;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多