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

Activity Lifecycle

The threads you create are not automatically aware of the changes in your activity's lifecycle. For example, a thread you spawned would not automatically be notified that your activity's onStop() method has been called, and the activity is not visible anymore, or that your activity's onDestroy() method has been called. This means you may need to do additional work to synchronize your threads with your application's lifecycle. Listing 5–20 shows a simply example of an AsyncTask still running even after the activity has been destroyed.

Listing 5–20. Computing a Fibonacci Number In the Background Thread and Updating the User Interface Accordingly

public class MyActivity extends Activity {     private TextView mResultTextView; ...

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