android - Can't show AlertDialog in DoInBackground -


i trying use alertdialog in android notify users runing in offline mode after checking internet connection.

i have used following codes:

protected void doinbackground(void... params) {             if (this.isonline()) {                     new getjson().execute();             } else {          alertdialog.builder builder1 = new alertdialog.builder(homefragment);         builder1.setmessage("internet connection not available. viewing news in offline mode.");         builder1.setcancelable(true);          alertdialog alert1 = builder1.create();         alert1.show();          try {             savefile = new saveintofile(filename);             jsonstr = savefile.read();             // log.d(tag,"offline data reading file");             if (!jsonstr.equals(null))                 new getdatas().execute();             else {              }         } catch (exception e) {             e.printstacktrace();          }     }     return null;  } 

but getting error on adding codes alertdialog. app works fine without codes alertdialog. can mistakes code , how can correct work well??

doinbackground() runs on separate thread, other main thread. can use ui elements on main thread. try using runonuithread() method inside doinbackground() show dialog.


Comments

Popular posts from this blog

javascript - IndexedDB error: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned -

amazon web services - When using Cognito credentials with AWS in a browser (javascript), keep getting "missing credentials" error -

c# - How to set the datatextfield value instead of the value on a drop down list? -