Android App Development for Beginners - · PDF fileActivities - Steps 1. Register the...
Transcript of Android App Development for Beginners - · PDF fileActivities - Steps 1. Register the...
![Page 1: Android App Development for Beginners - · PDF fileActivities - Steps 1. Register the activity in the app’s manifest. 2. Manage activity lifecycles appropriately](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/1.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/2.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/3.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/4.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/5.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/6.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/7.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/8.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/9.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/10.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/11.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/12.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/13.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/14.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/15.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/16.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/17.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/18.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/19.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022030404/5a7a14047f8b9a6c3c8b615d/html5/thumbnails/20.jpg)
19