android - Stop main thread and show progress dialog -


hello guys having async task points online , depending on these points must decide popup window should show on main thread . example if points less should show "buy points" screen else show "buy item" screen .i want show progressdialog until points loaded

if main thread stops until points loaded progress dialog won't show

   string str_result= new jsontask().execute("my url" + uid).get();  

if progress dialog shows points loaded wrong

 new jsontask().execute("my url" + uid); 

my async taks

 class jsontask extends asynctask<string, string, string> {      progressdialog  pdia;     @override     protected void onpreexecute() {         super.onpreexecute();        pdia = new progressdialog(popupactivity.this);         pdia.setmessage("loading...");         pdia.show();     }      @override     protected string doinbackground(string... params) {      // points here          return null;     }      @override     protected void onpostexecute(string result) {         super.onpostexecute(result);          system.out.println(result);         setrewardpoints(integer.parseint(result));          pdia.dismiss();     }  } 

how can show progressdialog , stop main thread executing until async task complete?

you should create new interface contains callback method method call in postexecute method giving parameter number of points returned

public interface jsontaskcallback{   public void pointsprocessing(int point);} 

now should create new property interface in jsontask class , add new constructor has parameter jsontaskcallback variable.

jsontaskcallback taskcallback;     public jsontask(jsontaskcallback taskcallback){            this.taskcallback = taskcallback; } 

after call jsontaskcallback$pointsprecessing method in postexecute method, after use statement:

 new jsontask(new jsontaskcallback(){       @override       public void pointsprocessing(int point){            // proccess result , show convenient popup window         }  }).execute("my url" + uid); 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -