Activities in Android Studio
The Activity class is a crucial component of an Android app, and the way
activities are launched and put together is a fundamental part of the
platform's application model. Unlike programming paradigms in which apps
are launched with a main() method, the Android system initiates code in
an Activity instance by invoking specific callback methods that
correspond to specific stages of its lifecycle.
Declare activities
To declare your activity, open your manifest file and add an
<activity> element as a child of the <application> element.
For example:
Declare intent filters
Intent filters are a very powerful feature of the Android platform. They
provide the ability to launch an activity based not only on an explicit
request, but also an implicit one.
Managing the activity lifecycle
Over the course of its lifetime, an activity goes through a number of
states. You use a series of callbacks to handle transitions between
states. The following sections introduce these callbacks.
onCreate()
You must implement this callback, which fires when the system creates
your activity. Your implementation should initialize the essential
components of your activityonStart()
As onCreate() exits, the activity enters the Started state, and the activity becomes visible to the user. onResume()
The system invokes this callback just before the activity starts interacting with the user.
The onPause() callback always follows onResume().
onPause()
The system calls onPause() when the activity loses focus and enters a Paused state.
onStop()
The system calls onStop() when the activity is no longer visible to the user.
onRestart()
The system invokes this callback when an activity in the Stopped state is about to restart. onDestroy()
Comments
Post a Comment