January 2012
Intermediate to advanced
282 pages
7h 4m
English
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; ...