use thread android code example
Example: thread example in android
//if your project supports java8, you can implement with lambda function
new Thread(() -> {
// do background stuff here
runOnUiThread(()->{
// OnPostExecute stuff here
});
}).start();