The Lifecycle of an Android Activity

Android applications can be multi-process, and the Android operating system allows multiple applications to run concurrently, provided memory and processing power is available. Applications can have background processes, and applications can be interrupted and paused when events such as phone calls occur. There can be only one active application visible to the user at a time‚ÄĒspecifically, a single application Activity is in the foreground at any given time.

The Android operating system keeps track of all Activity objects running by placing them on an Activity stack (see Figure 4.2).When a new Activity starts, the Activity on the top of the stack (the current foreground Activity) pauses, and the new Activity pushes onto the top of the stack.When that Activity finishes, that Activity is removed from the activity stack, and the previous Activity in the stack resumes.

I am the top Activity. User can see and interact with me!

I am the second Activity in the stack. If the user hits Back or the top Activity is destroyed, the user can see and interact with me again!

I am an Activity in the middle of the stack. Users cannot see and interact with me until everyone above me is destroyed.

I am an Activity at the bottom of the stack. If those Activities above me use too many resources, I will be destroyed!

Figure 4.2 The Activity stack.

Android applications are responsible for managing their state and their memory, resources, and data. They must pause and resume seamlessly. Understanding the different states within the Activity lifecycle is the first step to designing and developing robust Android applications.

Easy Software Profits

Easy Software Profits

Here's How Anyone Can Start, Build and Run their Own Successful Software Empire Without Knowing the First Thing About Programming, Scripting Or Any 'Coder' Stuff. There is no doubt about it software sells. Software has a high percieved value and it solves problems for people.  A claim that can't always be made for PDF books, Video products and the like.

Get My Free Ebook


Post a comment