Showing Progressdialog During Ui Thread Operation In Android
As I've asken on another question HERE it seems that the PackageManager.getInstalledPackages() doesn't play nice with Threading. As CommonsWare stated HERE: Perhaps the PackageMa
Solution 1:
As discovered, the loop to work through the applications takes awhile (which can be done in a separate thread), compared to the call to PackageManager.getInstalledPackages() (which has to be done on the UI thread).
Solution 2:
Use Async to do background work and show indicator while loading data.
in you onCreate(). call new AsyncCommonDataFetcher(this).execute();
publicclassAsyncCommonDataFetcherextendsAsyncTask<Void, Void, Void> {
ContextmContext=null;
privateProgressDialogmProgressIndicator=null;
publicAsyncCommonDataFetcher(Context ctx) {
mContext = ctx;
}
protectedvoidonPreExecute() {
mProgressIndicator = ProgressDialog.show(((Activity) mContext), null,
"Please wait", true);
}
@Overrideprotected Void doInBackground(Void... voids) {
// Do what ever work you like to do. It will do this in backgound and show user a indicator to wait.
}
@OverrideprotectedvoidonPostExecute(Void voidInstance) {
try {
if (mProgressIndicator != null) {
mProgressIndicator.hide();
mProgressIndicator.dismiss();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
Solution 3:
Try the following for ProgressDialog in the onCreate() of your activity
this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
ProgressDialog LoadingDialog = ProgressDialog.show(this, "", "Loading..", true);
And then dismiss it when the process causing the delay is over
LoadingDialog.dismiss();
Post a Comment for "Showing Progressdialog During Ui Thread Operation In Android"