
Android Activity Lifecycle, Toast, and Documentation Exploration
Explore the essential concepts of Android, including activity lifecycle management, toast notifications, and accessing online documentation. Understand how activities interact, the callback methods in activity classes, and how to declare activities in the AndroidManifest.xml file. Experiment with lab exercises and objective-driven exploration to enhance your Android development skills.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Android Topics 1. Android Activity Lifecycle and Experiment 2. Toast 3. Explore Online Android Documentation 4. Practice: In-Class App
Android Activity Every application has at least one activity class. A main activity is presented to the user when the application is launched for the first time. Example: Users of a banking app must first log into their accounts before they can pay bills or transfer money. Login is the main activity. Each activity can start another activity in order to perform different actions. Each time a new activity starts, the previous activity is paused and the Android system preserves its status.
Android Activity and the AndroidManifest.xml Activities must be declared in the AndroidManifest.xml file in order to be accessible to the system. The category of the main activity is specified as the top-levellauncher.
AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.trishcornez.mediaplayer"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Activity Class callback methods 1. onCreate() 2. onStart() 3. onResume() 4. onPause() 5. onStop() 6. onRestart() 7. onDestroy() A callback method gets called when an event occurs.
Toast: Development feature Example A Toast can be programmed to appear when an event occurs, such as when the user clicks a button or when an activity is created. A Toast appears and then vanishes.
Experiment : Lab 3 Exercise 1
Objective of Exploring Online Documentation Navigate documentation Research constructs Build apps that we have very little clue about at the start.
Development Tips Never build an entire app and then test it. Build and test in increments. Use development tools, such as Android logs and Toast to aid your process. Android Logs: Following certain events, include a message to the Android logs. For the Log tag, use the name of activity class. For the Log message, use a keyword name and a value. Toast: Can be used to display a temporary message box to the screen.
In-Class App: Sound Player The app is loaded with a sound (Mad Cow) Sound can be played. Sound can be paused and then played again, continuing at the pause point.
Where to begin? What do we know? 1. Sound is a media element. 2. This app requires MediaPlayer for Android. 3. MediaPlayer will need to be researched. 4. Sound is stored as raw data. 5. Create a raw directory in the resources directory and load it with an interesting sound.
Controller View Model
Overview of Development Tasks Task 1: Build a Layout for the app. Task 2: Test the app using Toast. Quick experiment. Task 3: Research MediaPlayer for sound. Task 4: Load the app with an interesting sound. Task 5: Implement the MediaPlayer . Task 6: Test the app: play the sound, pause it, and continue playing it. Task 7: Remove Toasts when done. No Stop action is added to this app. It requires a little more finesse.
Task 1: Build a Layout for the app. Task 2: Test the button using Toast. Quick experiment.
Task 3: Research MediaPlayer for sound. a. What is MediaPlayer? Is it a class or an object? b. What does the MediaPlayer state diagram tells us about playback controls? c. How do we play a sound or pause a sound? d. How do we start the playback of a sound. e. How do we resume playback for a paused MediaPlayer object? f. What is required to to play a specific sound? g. How do we identify a raw file?
Task 4: Load the app with an interesting sound.
Task 5: Implement the MediaPlayer . Task 6: Test the app: play the sound, pause it, and continue playing it. Task 7: Remove Toasts when done.