Only the source stream that created the view hierarchy can touch its views

Im adding a run dialog in some actions. But I get a mention of the exception in the header. How to solve it.

dialog = ProgressDialog.show(Notification.this, "loading please wait", "Loading. Please wait...", true); new Thread() { public void run() { try{ performBackgroundProcess1(); //sleep(3000,000); } catch (Exception e) { Log.e("tag", e.getMessage()); } // dismiss the progress dialog dialog.dismiss(); } }.start(); 

Any error with this.all The background process runs in the overbackgroundprocess method.

0
android progressdialog
source share
2 answers

You cannot call dialog.dismiss (); in the background thread. You can force threads to send messages to handlers when they are done, and in the handler you can reject the dialog. Handlers work in ui thread

There is a tutorial about it

0
source share

use runOnUiThread like:

  new Thread() { public void run() { try{ performBackgroundProcess1(); //sleep(3000,000); } catch (Exception e) { Log.e("tag", e.getMessage()); } // dismiss the progress dialog CurrentActivity.this.runOnUiThread(new Runnable(){ @Override public void run() { // TODO Auto-generated method stub dialog.dismiss(); } }); } }.start(); 
0
source share

All Articles