ProgressDialog : how to prevent Leaked Window
Use: progressDialog.dismiss(); in end work
Use: progressDialog.dismiss(); in end work
How about using setCancelable? Did you try it? From the Docs: Control whether the shown Dialog is cancelable. Use this instead of directly calling Dialog.setCancelable(boolean), because DialogFragment needs to change its behavior based on this For custom DialogFragment Add isCancelable = false at onCreateDialog
I had a very similar issue (which landed me here) and found a very simple fix for it. While my code is different, it should be easy to adapt. Here is my fix: public void showBox() { mActive = true; if (! ((Activity) mContext).isFinishing()) { mDialogBox.show(); } } So, in the sample code in the … Read more
I have added few lines in your code and now its working fine with progress bar. getWindow().requestFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.main ); // Makes Progress bar Visible getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); webview = (WebView) findViewById(R.id.webview); webview.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { //Make the bar disappear after URL is loaded, and changes string to Loading… setTitle(“Loading…”); … Read more
I did some testing and I feel that the best way to achieve this is doing a custom Dialog. Here is an example of what I did. This will answer question number 2 but will give you an idea of how to fix question number 1. public class MyProgressDialog extends Dialog { public static MyProgressDialog … Read more
/** * this class performs all the work, shows dialog before the work and dismiss it after */ public class ProgressTask extends AsyncTask<String, Void, Boolean> { public ProgressTask(ListActivity activity) { this.activity = activity; dialog = new ProgressDialog(activity); } /** progress dialog to show user that the backup is processing. */ private ProgressDialog dialog; /** application … Read more
ProgressDialog pd = new ProgressDialog(yourActivity.this); pd.setMessage(“loading”); pd.show(); And that’s all you need.
The method show() must be called from the User-Interface (UI) thread, while doInBackground() runs on different thread which is the main reason why AsyncTask was designed. You have to call show() either in onProgressUpdate() or in onPostExecute(). For example: class ExampleTask extends AsyncTask<String, String, String> { // Your onPreExecute method. @Override protected String doInBackground(String… params) … Read more
Declare your progress dialog: ProgressDialog progress; When you’re ready to start the progress dialog: progress = ProgressDialog.show(this, “dialog title”, “dialog message”, true); and to make it go away when you’re done: progress.dismiss(); Here’s a little thread example for you: // Note: declare ProgressDialog progress as a field in your class. progress = ProgressDialog.show(this, “dialog title”, … Read more
Fragments can actually make this a lot easier. Just use the method Fragment.setRetainInstance(boolean) to have your fragment instance retained across configuration changes. Note that this is the recommended replacement for Activity.onRetainnonConfigurationInstance() in the docs. If for some reason you really don’t want to use a retained fragment, there are other approaches you can take. Note … Read more