O'Reilly logo

Pro Android Apps Performance Optimization by Hervé Guihot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Threads

A Thread object, that is, an instance of the Thread class defined by Java, is a unit of execution with its own call stack. Applications can create additional threads easily, as shown in Listing 5–1. Of course, your application is free to create additional threads to perform some operations outside of the main thread; very often you will have to do exactly that to keep your application responsive.

Listing 5–1. Creating Two Threads

    // the run() method can simply be overridden…     Thread thread1 = new Thread("cheese1") {         @Override         public void run() {             Log.i(”thread1”, "I like Munster");         }     };     // …or a Runnable object can be passed to the Thread constructor     Thread thread2 = new Thread(new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required