how to run a task on ui thread. I am trying to run a task on ui thread
MainActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Mytask finished", Toast.LENGTH_SHORT).show(); } }); i found the solution for running task on ui thread in the fragment activity just change the MainActivity.this to getActivity() that will fix the error. i think this might help.
Thread timer = new Thread() { @Override public void run() { //do something getActivity().runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getActivity(), "Token Generated", Toast.LENGTH_SHORT).show(); } }); } }; timer.start();