Java/Android - How to set timeout external service call with handler -


my scenario oncreate() activity method executes following code (simplified):

dialog.show(); //loading wheel try {     remote.sendrequest(mydata, new myhandler()); } catch (exception e) {     dialog.dismiss();     //log , react     }  class myhandler extends sdkspecificcompiledhandler {      @override     public void failure() {         dialog.dismiss();         //do stuff     }      @override     public void success() {         dialog.dismiss();         //do stuff     }  }  //i have read-only access handler! public abstract class sdkspecificcompiledhandler {     public abstract void success(jsonobject successdata);     public abstract void failure(jsonobject errordata); } 

explanation: remote service called passing handler gets called when he's done. loading wheel (dialog) shown user until success, failure or exception happens.

the problem when service gets called no response ever comes. in case dialog.dismiss() doesn't called , loading wheel keeps spinning ever.

what need sort of timeout dismisses dialog (and possibly takes other actions) after seconds if server doesn't back.

my first though create new thread service call, , right after launch set timer dismisses dialog. idea?

thank you,

edit:

the service third-party/not editable. i'm using pre-compiled artifact.

it better use time out in service call itself, can set time out service , if need know how set time out should know kind of service using ?

one more thing if using loader should make loader in such way can cancel client.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -