20
Lesson 1 Basic Blocks Android App Development for Beginners 0

Android App Development for Beginners - · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Embed Size (px)

Citation preview

Page 1: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Lesson 1

Basic Blocks

Android App Development for Beginners

0

Page 2: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities

An activity is the entry point for interacting with the user.

Page 3: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities - Instagram example

List of new post Create new post Profile information

Page 4: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities - Steps

1. Register the activity in the app’s manifest.

2. Manage activity lifecycles appropriately

Page 5: Android App Development for Beginners -   · PDF fileActivities - 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>

Page 6: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

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.

Page 7: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities - onCreate()

The onCreate() callback fires when the system creates your activity

Page 8: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities - onStart()

This callback contains the activity’s final preparations for coming to the foreground and becoming interactive.

Page 9: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities - onResume()

The state in which the app interacts with the user is onResume().

Page 10: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities - onPause()

When an interruptive event occurs the system invokes the onPause()callback.

Page 11: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

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.

Page 12: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities - onRestart()

In the onRestart() callback, the app restores the state of the activity from the time that it was stopped.

Page 13: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Activities - onDestroy()

The system invokes the onDestroy()callback before an activity is destroyed

Page 14: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

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

Page 15: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

Intents - Start an activity

Intent i = new Intent(PostListActivity.this,

PostDetailActivity.class);

startActivity(i);and

Use startActivityForResult() to receive a result

Page 16: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

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()

Page 17: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

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);

Page 18: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

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.

Page 19: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

18

Page 20: Android App Development for Beginners -   · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately

19