I am having trouble with updating my recyclerview with notify data set changed, since it hangs the ui for a couple of seconds upon called. After searching on the net, it was suggested to update the adapter on the background thread.
private synchronized void updateAdapter() {
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
public Void doInBackground(Void... params) {
adapter.notifyDataSetChanged();
return null;
}
};
task.execute();
}
And upon running this line of code, the app crashed with the error,
"Only the original thread that created a view hierarchy can touch its views."
And upon searching further, it was suggested that the solution was to run on the ui thread.
runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
Which brings me back to my initial problem. How should i handle this problem? Any help is appreciated. Thank you.