简体   繁体   中英

ProgressDialog not responding

Hello guys why when i add ProgressDialog it become not responding

            ProgressDialog dialog = ProgressDialog.show(AppsInspectorActivity.this, "", 
                    "Scanning package " + pkgInfo.packageName, true);
            dialog.setCancelable(true);
            dialog.show();

at above Log.v(TAG, "Scanning package " + pkgInfo.packageName);

private List<PackageInfo> getAdPackages() {

[HEAVY STUFF]

    return new ArrayList<PackageInfo>(adPackages);
}

}

ASyncTask is the way to go. just override doInBackground(). and use a Handler class for stopping (dismiss()) the progressDialog.

http://www.helloandroid.com/tutorials/using-threads-and-progressdialog seems useful..

http://www.vogella.de/articles/AndroidPerformance/article.html very in-depth version..

Can you define what not responding means? Does the dialog never display, or simply not dismiss when you press Back? When the operation is complete, try to dismiss the dialog with:

dialog.dismiss()

So I am going to take a guess at the problem, if your saying that the progress dialog freezes and the app becomes non responsive, it appears that you haven't threaded the long term process that the dialog is designed to represent. By default all code is ran on the UI thread, so if your process takes to long, the screen doesn't update and the user gets the notification of death (Not responding). You should thread long term processes (preferably in an async task) and post updates to the progress dialog as needed in the onProgressUpdate method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM