xAnGz
xAnGz

Reputation: 127

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);
}

}

Upvotes: 0

Views: 196

Answers (3)

Drake Justice KDE
Drake Justice KDE

Reputation: 51

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..

Upvotes: 1

Ashterothi
Ashterothi

Reputation: 3282

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.

Upvotes: 0

RealCasually
RealCasually

Reputation: 3613

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()

Upvotes: 0

Related Questions