Let's say I have an activity showing some content on the screen. I need to execute some method (asyncMethod) asynchronously, and when this is done, I need to update the data on the screen. What is the most correct and easiest way to do this?
Currently, the easiest way I know is to use a stream:
new Thread(new Runnable() { public void run() { asyncMethod(); } }).start();
I am familiar with AsyncTask, but it is more complicated than using a thread, and for each method that I need to run asynchronously, I need to create a new AsyncTask, while this greatly increases the size of the code.
I thought of some kind of general AsincTask that receives a method as a parameter and how it executes it, but as far as I know, in Java it is impossible to pass methods as parameters.
In other words, I'm looking for the most compact (but correct) way to execute methods asynchronously.
Misha source share