Android how to runOnUiThread in other class?
android, asynchronous, multithreading
Solution
Here's a solution if you don't want to pass the context:
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
// code goes here
}
});
Problem
In my application, in MainActivity, there is a thread which works fine. But when I call another class to get data from the server I can't run on a thread. See code example below. ``` class MainActivity extends Activity implements Runnable { public void onCreate() { new Thread(this).start(); } public void run() { //here is code for download data from server after completion this and in handler i m call other class in setdata() method.... } public void setData() { new CheckData(this); } } class CheckData { public CheckData(Context context) { context.runUIonthread(){//cant call as runUIthread............ } } ```