Lecture 6 - First Part
Lecture 6 - First Part
Proliferate Gratification!
1. Introduction to Activities
Let's consider WhatsApp, a popular messaging app, to understand how activities work in a real-world
scenario.
o Functionality: Users can scroll through their chat history, click on a chat to open
it, start a new chat, or access settings.
2. Chat Activity:
o Description: When a user selects a chat from the main screen, this activity opens,
showing the conversation with a specific contact or group.
o Functionality: Users can send and receive messages, share media (photos,
videos, voice notes), and perform actions like calling the contact or viewing their
profile.
3. Contacts Activity:
o Description: This screen allows users to browse their contacts to start a new
chat.
o Functionality: Users can search for contacts, view contact details, and initiate a
new chat or call.
4. Status Activity:
o Description: This screen displays the status updates of the user's contacts.
o Functionality: Users can view status updates, reply to them, and post their own
status updates.
5. Call Activity:
o Description: This screen shows the call history and allows users to make voice or
video calls.
o Functionality: Users can view recent calls, make new calls, and see missed call
notifications.
6. Settings Activity:
o Description: This screen provides access to app settings.
o Functionality: Users can change their profile picture, update status, configure
privacy settings, manage notifications, and access help.
2. EXAMPLE
3.1 AndroidManifest.xml
- Purpose: The manifest file provides essential information about your app to the Android
system, which the system must have before it can run any of the app's code.
- Declaration Example:
xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
- onResume(): Called when the activity will start interacting with the user.
java
@Override
protected void onResume() {
super.onResume();
// Code to execute when the activity starts interacting with the user
}
- onPause(): Called when the system is about to put the activity into the background.
java
@Override
protected void onPause() {
super.onPause();
// Code to execute when the activity is about to go into the background
}
java
@Override
protected void onDestroy() {
super.onDestroy();
// Code to execute before the activity is destroyed
}
- onRestart(): Called after the activity has been stopped, just before it is started again.
java
@Override
protected void onRestart() {
super.onRestart();
// Code to execute when the activity is restarted
}
5. Homework
- Research: Explore different scenarios where each lifecycle method is particularly useful.
- Practice: Create an app with multiple activities and experiment with different lifecycle
methods.
- Explore: Modify the Android Manifest file to add additional activities and experiment with
different configurations.
By the end of Day 6, students should have a solid understanding of activities in Android, their
lifecycle, how to create them, and how to manage their states effectively. This foundational
knowledge will be crucial for building more complex applications in the following days.