Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Topics Android Activity Lifecycle and Experiment Toast

Similar presentations


Presentation on theme: "Android Topics Android Activity Lifecycle and Experiment Toast"— Presentation transcript:

1 Android Topics Android Activity Lifecycle and Experiment Toast
Explore Online Android Documentation Practice: In-Class App

2 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.

3 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.

4 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android=" package="com.example.trishcornez.mediaplayer"> <application android:allowBackup="true" android:supportsRtl="true" <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>

5 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.

6

7 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.

8 Experiment : Lab 3 Exercise 1

9 Objective of Exploring Online Documentation
Navigate documentation Research constructs Build apps that we have very little clue about at the start.

10 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.

11 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. 

12 Where to begin? What do we know?
Sound is a media element. This app requires MediaPlayer for Android. MediaPlayer will need to be researched. Sound is stored as raw data. Create a raw directory in the resources directory and load it with an interesting sound.

13 Controller View Model

14 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.

15 Task 1: Build a Layout for the app.
Task 2: Test the button using Toast. Quick experiment.

16 Task 3: Research MediaPlayer for sound.
What is MediaPlayer? Is it a class or an object? What does the MediaPlayer state diagram tells us about playback controls? How do we play a sound or pause a sound? How do we start the playback of a sound. How do we resume playback for a paused MediaPlayer object? What is required to to play a specific sound? How do we identify a raw file?

17 Task 4: Load the app with an interesting sound.

18 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.


Download ppt "Android Topics Android Activity Lifecycle and Experiment Toast"

Similar presentations


Ads by Google