Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google. With a user interface based on direct manipulation, Android is designed primarily for touchscreen mobile devices such as smartphones and tablet computers, with specialized user interfaces for televisions (Android TV), cars (Android Auto), and wrist watches (Android Wear).
- Content Provider
- Broadcast Receiver
An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen
One activity in an application is specified as the “main” activity, which is presented to the user when launching the application for the first time.
Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the “back stack”). When a new activity starts, it is pushed onto the back stack and takes user focus.
The back stack maintain the basic “last in, first out” mechanism, so, when the user is done with the current activity and presses the BACK key, it is popped from the stack (and destroyed) and the previous activity resumes.
To create an activity, you must create a subclass of Activity (or an existing subclass of it). In your subclass, you need to implement call back methods that the system calls when the activity transitions between various states of its lifecycle, such as when the activity is being created, stopped, resumed, or destroyed.
onCreate // The activity is being created.
onStart() //The activity is about to become visible.
onResume() // The activity has become visible (it is now “resumed”).
onPause() // Another activity is taking focus (this activity is about to be “paused”).
onStop() // The activity is no longer visible (it is now “stopped”)
onDestroy() // The activity is about to be destroyed.
You can shut down an activity by calling its finish() method. You can also shut down a separate activity that you previously started by calling finishActivity().
Managing the lifecycle of your activities by implementing callback methods is crucial to developing a strong and flexible application. The lifecycle of an activity is directly affected by its association with other activities, its task and back stack.
A activity can exist in basically three states: Resumed, Paused, Stopped
The call back method in which you can save information about the current state of your activity is onSavedInstancestate(). The system calls this method before making the activity vulnerable to being destroyed and passes it a Bundle object. The Bundle is where you can store state information about the activity as name-value pairs, using methods such as putstring(). Then, if the system kills your activity’s process and the user navigates back to your activity, the system passes the Bundle to onCreate() so you can restore the activity state you saved during onSavedInstancestate(). If there is no state information to restore, then the Bundle passed to onCreate() is null.
When an activity is paused or stopped, the state of the activity is retained. This is true because the Activity object is still held in memory when it is paused or stopped all information about its members and current state is still alive. Thus, any changes the user made within the activity are retained in memory, so that when the activity returns to the foreground (when it “resumes”), those changes are still there.
The order for lifecycle callbacks is all around characterized, especially when the two activities are in a similar procedure and one is beginning the other. Here’s the order for tasks that happen when Activity A beginnings Activity B:
- Activity A’s onPause() method executes.
- Activity B’s onCreate(), onStart(), and onResume() methods execute in sequence.
- (Activity B now has user focus.)Then, if Activity A is no longer visible on screen, its onStop() method executes.