Android: ProgressDialog throws exception, after activity change [RESOLVED] -


06-27 15:35:26.598: e/androidruntime(18210): fatal exception: main 06-27 15:35:26.598: e/androidruntime(18210): process: com.radioplymouth.radioplymouth, pid: 18210 06-27 15:35:26.598: e/androidruntime(18210): android.view.windowmanager$badtokenexception: unable add window -- token android.os.binderproxy@41bf7a90 not valid; activity running? 06-27 15:35:26.598: e/androidruntime(18210):    @ android.view.viewrootimpl.setview(viewrootimpl.java:597) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:259) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:94) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.app.dialog.show(dialog.java:291) 06-27 15:35:26.598: e/androidruntime(18210):    @ com.radioplymouth.radioplymouth.mainactivity$1.onreceive(mainactivity.java:132) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.support.v4.content.localbroadcastmanager.executependingbroadcasts(localbroadcastmanager.java:297) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.support.v4.content.localbroadcastmanager.access$000(localbroadcastmanager.java:46) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.support.v4.content.localbroadcastmanager$1.handlemessage(localbroadcastmanager.java:116) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.os.handler.dispatchmessage(handler.java:102) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.os.looper.loop(looper.java:157) 06-27 15:35:26.598: e/androidruntime(18210):    @ android.app.activitythread.main(activitythread.java:5872) 06-27 15:35:26.598: e/androidruntime(18210):    @ java.lang.reflect.method.invokenative(native method) 06-27 15:35:26.598: e/androidruntime(18210):    @ java.lang.reflect.method.invoke(method.java:515) 06-27 15:35:26.598: e/androidruntime(18210):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1069) 06-27 15:35:26.598: e/androidruntime(18210):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:885) 06-27 15:35:26.598: e/androidruntime(18210):    @ dalvik.system.nativestart.main(native method) 

the progress dialog .show() in broadcast receiver, on mainactivity. mediaplayer service sends broadcast, loading, done or error relates receiver(s) on main

broadcastreceiver loadingreceiver = new broadcastreceiver(){      @suppresslint("newapi")     @override     public void onreceive(context arg0, intent arg1) {          progress = new progressdialog(mainactivity.this);         progress.settitle("loading");         progress.setmessage("loading radioplymouth...");         progress.show(); //error here         player.setimageresource(r.drawable.stop);     } }; 

when app first opened (mainactivity first created), works 100% fine no issues. when change activity, & try start service again, error thrown. research error, majority of reasonings mis-spelling or passing incorrect context, instead of activitycontext.this (as seen above).

if come out of activity, can work again, times have forcestop or reinstall

update:

@override     protected void onpause(){     super.onpause();     progress.dismiss(); } 

i included method mainactivity, problem still persists. (i tryed variations of .cancel(), using if .isshowing())

well somthing wrong somewhere. after removal of onpause override, able move around activitys fine, after returning mainactivity, loading service/progress dialog brings crash original line causes ( , vice versa). part of me knows if exclude whole progressdialog section project, run fine, need have form of visual notification of loading.

in reference jitain-sharma's comment; in broadcast receiver, progress dialog defined new. surely solve issues tokens user have on mainactivity window before progress dialog gets called?

resolved: found calling progress.show() within if(!isfinishing()) solved issue.

the problem mainactivity.this

you using mainactivity context when activity class running.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -