0% found this document useful (0 votes)
28 views

Android Core Topics: (Introduction To Activities)

The document discusses the Activity class in Android, which represents screens in an app. Activities have a lifecycle managed through callback methods like onCreate(), onStart(), onResume(), etc. Developers must declare activities in the app manifest, including attributes and intent filters. Permissions can control which apps can start activities. The document provides details on configuring activities and handling their lifecycles.

Uploaded by

Rmae Longakit
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Android Core Topics: (Introduction To Activities)

The document discusses the Activity class in Android, which represents screens in an app. Activities have a lifecycle managed through callback methods like onCreate(), onStart(), onResume(), etc. Developers must declare activities in the app manifest, including attributes and intent filters. Permissions can control which apps can start activities. The document provides details on configuring activities and handling their lifecycles.

Uploaded by

Rmae Longakit
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

RHEA MAE L.

PERITO, MSIS
Subject Instructor
Free Electives 3

ANDROID CORE
TOPICS
(INTRODUCTION TO ACTIVITIES)
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.

Source: https://developer.android.com/guide/
The Concept of Activities: Mobile App
Experience
 Scenario: Opening an email app
way1: opening the app in the home
screen
way2: through social media app that
launches your email and go directly
to the email app's screen for
composing an email.

Source: https://developer.android.com/guide/
 The Activity class is designed to
facilitate a paradigm that is when one
app invokes another, the calling app
invokes an activity in the other app,
rather than the app as an atomic whole.
 You implement an activity as a subclass
of the activity.

Source: https://developer.android.com/guide/
 Generally, one activity implements one
screen in an app.

Source: https://developer.android.com/guide/
main activity
 is the first screen to appear when the
user launches the app.

Source: https://developer.android.com/guide/
 Each activity is only loosely bound to the
other activities; there are usually minimal
dependencies among the activities in an
app. In fact, activities often start up activities
belonging to other apps.
*For example, a browser app might
launch the Share activity of a social- media
app.

Source: https://developer.android.com/guide/
CONFIGURING THE
MANIFEST

Source: https://developer.android.com/guide/
For your app to be able to use
activities, you must declare the
activities, and certain of their
attributes, in the manifest.

Source: https://developer.android.com/guide/
Declare activities
 open your manifest file and add an <activity> element
as a child of the <application> element.
For example,

<manifest ... >


  <application ... >
      <activity android:name=".ExampleActivity" />
      ...
  </application ... >
  ...
</manifest >

Source: https://developer.android.com/guide/
The only required attribute for this
element is android:name, which specifies
the class name of the activity. You can also
add attributes that define activity
characteristics such as label, icon, or UI
theme.

Source: https://developer.android.com/guide/
<activity> element Reference
Documentation

Link:
https://developer.android.com/guide/topics/
manifest/activity-element

Source: https://developer.android.com/guide/
<activity android:allowEmbedded=["true" | "false"]
          android:allowTaskReparenting=["true" | "false"]
          android:alwaysRetainTaskState=["true" | "false"]
          android:autoRemoveFromRecents=["true" | "false"]
          android:banner="drawable resource"
          android:clearTaskOnLaunch=["true" | "false"]
          android:colorMode=[ "hdr" | "wideColorGamut"] >  
  ...
</activity>

Source: https://developer.android.com/guide/
DECLARE THE INTENT
FILTERS

Source: https://developer.android.com/guide/
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.

Source: https://developer.android.com/guide/
Intent filters
For example, an explicit request might tell
the system to “Start the Send Email activity in
the Gmail app".
By contrast, an implicit request tells the
system to “Start a Send Email screen in any
activity that can do the job.“
When the system UI asks a user which app
to use in performing a task, that’s an intent filter
at work.

Source: https://developer.android.com/guide/
<activity android:name=".ExampleActivity“
android:icon="@drawable/app_icon">
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
    </intent-filter>
</activity>

Source: https://developer.android.com/guide/
DECLARE PERMISSIONS

Source: https://developer.android.com/guide/
 You can use the manifest's <activity> tag to
control which apps can start a particular
activity.
 A parent activity cannot launch a child
activity unless both activities have the
same permissions in their manifest.
 If you declare a <uses-permission> element for a
particular activity, the calling activity must
have a matching<uses-permission> element.

Source: https://developer.android.com/guide/
For example, if your app wants to use
a hypothetical app named SocialApp
to share a post on social media,
SocialApp itself must define the
permission that an app calling it must
have:

Source: https://developer.android.com/guide/
<manifest>
<activity android:name="...."
   android:permission=”com.google.socialapp.permission.SHARE_POST”

/>

Then, to be allowed to call SocialApp, your app


must match the permission set in SocialApp's
manifest:

<manifest>
   <uses-permission
android:name="com.google.socialapp.permission.SHARE_POST" />
</manifest>

Source: https://developer.android.com/guide/
Managing the activity lifecycle
 An activity goes to a number of
states.
 We use a series of callbacks to
handle transitions between states.

Source: https://developer.android.com/guide/
Callbacks
onCreate()
 We must implement this callback, which fires
when the system creates our activity. Our
implementation should initialize the essential
components of our activity.
 This is where we must all setContentView() to
define the layout for the activity’s user
interface.

Source: https://developer.android.com/guide/
onStart()
 As onCreate() exits, the activity enters the
Started state, and the activity becomes
visible to the user.
 Contains what amounts to the activity’s final
preparations for coming to the foreground
and becoming interactive.

Source: https://developer.android.com/guide/
onResume()
 The system invokes this callback just before
the activity starts interacting with the user.
 At this point, the activity is at the top of the
activity stack, and captures all user input.
 Most of an app’s core functionality in
implemented in this callback.

Source: https://developer.android.com/guide/
onPause()
 The system calls onPause() when the
activity loses focus and enters Paused
state.
 When the system calls it for your activity, it
technically means your activity is still
partially visible.
 But most often is an indication that the user
is leaving the activity, and the activity will
soon enter the Stopped or Resumed state.

Source: https://developer.android.com/guide/
onStop()
 The system calls onStop() when the activity
is no longer visible to the user.
 This may happen because the activity is
being destroyed, a new activity is starting,
or an existing activity is entering a
Resumed state and is covering the stopped
activity.

Source: https://developer.android.com/guide/
onRestart()
 This is invoked when an activity in the
Stopped state is about to restart.
 Restores the state of the activity from
the time that it was stopped.

Source: https://developer.android.com/guide/
onDestroy()
 The system invokes this callback before an
activity is destroyed.
 This callback in the final one that the activity
receives.
 It is usually implemented to ensure that all of
an activity’s resources are released when
the activity, or the process containing it, is
destroyed.

Source: https://developer.android.com/guide/

You might also like