Pass the activity into your stream and use it from the inside to access your views.
// from your activity: myExternalThread = new MyCustomCode(this); // <-- activity passed // your "simulation process" constructor: public MyCustomCode(Activity parent) { this.parent = parent; } // and when you want to access views: parent.runOnUiThread(new Runnable() { @Override public void run() { parent.findViewById(R.id.text_view); ... do something to your UI ... } });
My preferred way to create these external tasks is to use AsyncTask (then you don't have to worry about runOnUiThread , among other benefits). I do not know if this is relevant to your case, but you should check it.
source share