From ◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞◜◝◟◞
Jump to: navigation, search

Android Activity Lifecycle

Activity Lifecycle

In Android OS, almost all apps start and end with an activity.

Activities get created, paused, stopped and destroyed. These lifecycle changes need to be handled gracefully.

There are many lifecycle methods.

Android OS is responsible for recreating the activity, therefore the developer is only responsible for saving and restoring the activity state.

For example, when screen orientation changes, activities are stopped and recreated. This is because orientations require different layouts and those layouts require different resources, activities are always recreated on an orientation change. By default, if you rotate the screen, an activity will be restarted, however if you hook into the right lifecycle events, we can save off the position when the activity stops and restore that position when it gets recreated, creating the illusion of seamlessness.

Saving Instance State