Can't resolve CalledFromWrongThreadException with Handler

Posted by michel on Stack Overflow See other posts from Stack Overflow or by michel
Published on 2010-05-12T12:53:55Z Indexed on 2010/05/12 13:04 UTC
Read the original article Hit count: 303

Filed under:
|
|

I will try to keep it simple:

In my main activity I make a handler:

public class ARViewer extends ARDisplayActivity {

    public final MHandler mHandler = new MHandler(this);

 public void onCreate(Bundle savedInstanceState) {
...

The class MHandler:

public final class MHandler extends Handler{

        //main activity
 private ARViewer arnv;

        public MHandler(ARViewer arnv){
  this.arnv = arnv;
 }

        @Override
 public void handleMessage(Message msg) {
            ...
            case H_RR :
                  arnv.setContentView(R.layout.routeplanner);    
                  break;
            ...
  super.handleMessage(msg);
 }
}

But if I call the handleMessage method from a callback function in a other Class, definitely from a other thread, I still get the exception message: CalledFromWrongThreadException (Only the original thread that created a view hierarchy can touch its views) :

public void rFound(Route route) {
           Message msg = new Message();
           msg.what = MHandler.H_RR;
           ARViewer.arnv.mHandler.handleMessage(msg);
}

© Stack Overflow or respective owner

Related posts about android

Related posts about exception