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 ...

Get Pro Android Apps Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.