I have a main class, a worker thread class and it separated. In main thread, I pass input to worker thread and ask for it to work. When it finish, I want it to send back result
Maybe you should try AsynTask
, it is designed for just that:
private class MyThread extends AsyncTask {
protected Long doInBackground(URL... urls) {
// Calculate and return retulst
}
protected void onPostExecute(Long result) {
// This is executed in main Thread, use the result
}
}
You execute this thread like this:
new MyThread().execute(params, ...);
See http://developer.android.com/reference/android/os/AsyncTask.html