How to return AlertDialogs from a generic class in Android? -


within public class doesn't extend other class i'm doing evaluation stuff , return dialog if needs communicated user.

i'm using asynctask run method of instance of class main ui:

private onlineactivities onlineactivities = new onlineactivities();  new doonlineactivity().execute(getapplicationcontext());  private class doonlinestuff extends asynctask<context, integer, dialog> {     @override     protected dialog doinbackground(context... params) {         return onlineactivities.start(params[0]);     }      @override     protected void onprogressupdate(integer... progress) {         log.v(runtimevars.getmyname(), "asynconlinetask in progess");     }      @override     protected void onpostexecute(dialog result) {         if (result != null)             result.show();     } } 

now, public dialog start() method of onlineactivities.java creates dialog using context assigned via it's parameter.

when dialog returned onpostexecute receive following exception

11-14 23:53:43.303: error/androidruntime(1320): fatal exception: main 11-14 23:53:43.303: error/androidruntime(1320): android.view.windowmanager$badtokenexception: unable add window -- token null not application 11-14 23:53:43.303: error/androidruntime(1320):     @ android.view.viewroot.setview(viewroot.java:509) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:177) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:91) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.app.dialog.show(dialog.java:241) 11-14 23:53:43.303: error/androidruntime(1320):     @ info.myproject.messaging.conversationlist$doonlineactivity.onpostexecute(conversationlist.java:245) 11-14 23:53:43.303: error/androidruntime(1320):     @ info.myproject.messaging.conversationlist$doonlineactivity.onpostexecute(conversationlist.java:1) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.os.asynctask.finish(asynctask.java:417) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.os.asynctask.access$300(asynctask.java:127) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:429) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.os.handler.dispatchmessage(handler.java:99) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.os.looper.loop(looper.java:123) 11-14 23:53:43.303: error/androidruntime(1320):     @ android.app.activitythread.main(activitythread.java:4627) 11-14 23:53:43.303: error/androidruntime(1320):     @ java.lang.reflect.method.invokenative(native method) 11-14 23:53:43.303: error/androidruntime(1320):     @ java.lang.reflect.method.invoke(method.java:521) 11-14 23:53:43.303: error/androidruntime(1320):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 11-14 23:53:43.303: error/androidruntime(1320):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 11-14 23:53:43.303: error/androidruntime(1320):     @ dalvik.system.nativestart.main(native method) 

i suppose cannot use context this. alternative? how can outsource basic stuff need do, general dialogs?

do need use custom intents instead?

don't this. pass context constructor. , show activity before go in background , clear after.

new doonlineactivity().execute(getapplicationcontext());  private class doonlinestuff extends asynctask<void, integer, dialog> {      context ctx;     dialog dialg      public doonlinestuff(context ctx){      this.ctx = ctx;  }       @override     protected void onpreexecute(){     dialg = createdialog;     dialog.show() }      @override     protected dialog doinbackground(void... void) {         // stuff in background         publishprogress(0);     }      @override     protected void onprogressupdate(integer... progress) {         log.v(runtimevars.getmyname(), "asynconlinetask in progess");     }      @override     protected void onpostexecute(dialog result) {         dialog.dismiss()  } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -