Displaying a progress wheel on main screen while connecting to internet [Android] -


i want display progress bar loads while connecting internet in logo screen. using below class check internet connection:

 public class appstatus {     public boolean isnetworkavailable(final context context) {         final connectivitymanager connectivitymanager = ((connectivitymanager) context.getsystemservice(context.connectivity_service));         return connectivitymanager.getactivenetworkinfo() != null && connectivitymanager.getactivenetworkinfo().isconnected();     } } 

the code of screen progress bar is:

public class logo_activity extends appcompatactivity {     private progressbar mprogress;     private int mprogressstatus = 0;     private handler mhandler = new handler();     private appstatus con = new appstatus();      @override     protected void oncreate(bundle savedinstancestate) {          requestwindowfeature(window.feature_no_title);         getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_logo_activity);         mprogress = (progressbar) findviewbyid(r.id.progressbar);          new thread(new runnable() {             public void run() {                 if (con.isnetworkavailable(getapplicationcontext()))                 {                     mprogressstatus += 10;                    //user authentication in background.                 }                 else {                     mprogressstatus +=10;                    // display alert dialog box connect internet launching settings activity.                  }                  // update progress bar                 mhandler.post(new runnable() {                     public void run() {                         mprogress.setprogress(mprogressstatus);                     }                 });             }         }).start();      } } 

the problems facing alert dialog box not displaying , when launch activity settings , exit without turning on internet, screen stuck on loading screen only. can please write asynctask method it. can't seem around it.

thanks.

the problem new thread have created still runs on ui thread, nothing displayed because ui locked. need use assynctask. here tutorial.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -