1

我正在使用 Handler 调用 WebServices 并在


// 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 是被解雇。

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

4

1 回答 1

2

我在这里只添加了一行条件。
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;
    }
}
于 2012-11-06T06:45:00.480 回答