Monday, March 14, 2016

Accesing UI From Thread of AcyncTask

Handler can is defined in the Activity top level


public class MyActivity extends Activity{

...

private Handler handler = new Handler(Looper.getMainLooper()) {
    @Override
    public void handleMessage(Message msg) {
    Log.i(P.TAG, "Handler got message");
    if (msg.what == GOT_RECIEVER_HOST) {
    Log.i(P.Tag, "GOT_RECIEVER_HOST");
              Toast.makeText(ctxStatic, "Motion Detected", Toast.LENGTH_LONG).show();
      }
    }
    };

...
}


From a Thread, or AsyncTask in the Activity


handler.sendEmptyMessage(GOT_RECIEVER_HOST);

No comments:

Post a Comment