Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best method for threading in Android?

I have an animation in which triggers an event. This event fires a lot of computing usage and thus stutters the UI.

What I need to do is keep the thread running smoothly. When the event happens it will pass a string down to the thread, perform calculations (including using the audioRecord class) and return a boolean variable.

I have looked around and it seems AsyncTask may be the best solution, but I wanted to see if any of you had any ideas? Considering performance, Is this the best way to go?

Thanks,

Ben

like image 569
Ben Taliadoros Avatar asked Jan 01 '26 00:01

Ben Taliadoros


1 Answers

Generally AsyncTask is fine. But if you dont need to acess the UI thread for your background operation you can simply use a new thread.

new Thread(new Runnable() {
    public void run() {
        //do stuff
    }
}).start();
like image 174
Michele Avatar answered Jan 02 '26 12:01

Michele