android app development for beginners - · pdf fileactivities - steps 1. register the...
TRANSCRIPT
Lesson 1
Basic Blocks
Android App Development for Beginners
0
Activities
An activity is the entry point for interacting with the user.
Activities - Instagram example
List of new post Create new post Profile information
Activities - Steps
1. Register the activity in the app’s manifest.
2. Manage activity lifecycles appropriately
Activities - Register the activity in the manifestDeclare the activity in the application's
manifest file adding an <activity> element as a child of the <application> element.
<?xml version="1.0" encoding="utf-8"?>
<manifest … >
<application … >
<activity android:name=".MoviesActivity" />
…
</application>
...
</manifest>
Activities - Manage Lifecycle
To create an android activity we need implement it as a subclass of the Activity class. This Activity class is part of the Android API classes.
Activities - onCreate()
The onCreate() callback fires when the system creates your activity
Activities - onStart()
This callback contains the activity’s final preparations for coming to the foreground and becoming interactive.
Activities - onResume()
The state in which the app interacts with the user is onResume().
Activities - onPause()
When an interruptive event occurs the system invokes the onPause()callback.
Activities - onStop()
When your activity is no longer visible to the user, it has entered the Stopped state, and the system invokes the onStop() callback.
Activities - onRestart()
In the onRestart() callback, the app restores the state of the activity from the time that it was stopped.
Activities - onDestroy()
The system invokes the onDestroy()callback before an activity is destroyed
Intents
An Intent is a messaging object you can use to request an action from another app component:
● Start an activity● Start a service● Delivering a broadcast
Intents - Start an activity
Intent i = new Intent(PostListActivity.this,
PostDetailActivity.class);
startActivity(i);and
Use startActivityForResult() to receive a result
Intents - Start a service and Deliver a broadcastA service is a component that performs
operations in the background without a user interface.
startService()
A broadcast is a message that any app can receive.
sendBroadcast()
or
sendOrderedBroadcast()
Intents - Explicit intents
Used to launch a specific app component, such as a particular activity or service in your app.
Intent downloadIntent = new Intent(this, DownloadService.class);
downloadIntent.setData(Uri.parse(fileUrl));
startService(downloadIntent);
Intents - Implicit intents
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
sendIntent.setType("text/plain");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}
An implicit intent specifies an action that can invoke any app on the device able to perform the action.
18
19