Professional Documents
Culture Documents
12
13
System and user apps
● System apps have no special status
● The system apps function both as apps for users and to
provide key capabilities that developers can access from
their own app. For example, if your app would like to
deliver an SMS message, you don't need to build that
functionality yourself—you can instead invoke whichever
SMS app is already installed to deliver a message to the
recipient you specify.
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 14
Android
4.0 International License
Java API Framework
The entire feature-set of the Android OS is available to you
through APIs written in the Java language.
● View class hierarchy to create UI screens
● Resource manager
● Notification manager
● Activity manager for life cycles and navigation
● Content providers to access data from other apps
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 15
Android
4.0 International License
Android runtime
For devices running Android version 5.0 (API level 21) or higher, each app
runs in its own process and with its own instance of the Android Runtime
(ART). ART is written to run multiple virtual machines on low-memory
devices by executing DEX files, a bytecode format designed specially for
Android that's optimized for minimal memory footprint. Build toolchains,
such as Jack, compile Java sources into DEX bytecode, which can run on
the Android platform.
Prior to Android version 5.0 (API level 21), Dalvik was the Android runtime
21
Android Q Or Android 10. Breaking the 10-year history of
naming Android releases after desserts, Google in 2019
announced the new version as just Android 10.
Google has released its latest big update in 2020 called
Android 11 “R”, which is rolling out now to the firm's Pixel
devices, and to smartphones from a handful of third-party
manufacturers.
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 22
Android
4.0 International License
App Development
● Use AppCompat
● Generating layout
file is convenient
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 36
Android
4.0 International License
Android Studio Panes
Layout
Editor
Project
Files
Android Monitors:
logcat: log messages
2. Select virtual
or physical
device
3. OK
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 40 40
Android
4.0 International License
Create a virtual device
Use emulators to test app on different versions of Android and form factors.
Views
Button CheckBox
EditText RadioButton
Slider Switch
android:<property_name>="@<resource_type>/resource_id"
Example: android:text="@string/button_label_next"
android:<property_name>="@+id/view_id"
Example: android:id="@+id/show_count"
linearL.addView(myText);
setContentView(linearL);
● Enable Autoconnect in
toolbar if disabled
● Drag element to any part
of a layout
● Autoconnect generates
constraints against
parent layout
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 78
Android
4.0 International License
ConstraintLayout handles
1. Resizing handle
2. Constraint line and handle
3. Constraint handle
4. Baseline handle
● View:
R.id.recyclerview
rv = (RecyclerView) findViewById(R.id.recyclerview);
● String:
In Java: R.string.title
In XML: android:text="@string/title"
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 97
Android
4.0 International License
Measurements
● Density-independent Pixels (dp): for Views
● Scale-independent Pixels (sp): for text
Activities and
Intents
Lesson 2
This
Thiswork
workis islicensed
licensedunder
undera aCreative
Creative
Introduction to
Android Developer Fundamentals Activities Commons
CommonsAttribution-NonCommercial
Attribution-NonCommercial 99
Android
4.0
4.0International
InternationalLicense
License
Activities
(high-level view)
setContentView(R.layout.activity_main);
}
Resource is layout in this XML file
}
<activity android:name=".MainActivity">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 112
Android
4.0 International License
Intents
Intent Action
Android
System
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 114
Android
4.0 International License
What can intents do?
● Start activities
○ A button click starts a new activity for text entry
○ Clicking Share opens an app that allows you to post a photo
● Start services
○ Initiate downloading a file in the background
● Deliver broadcasts
○ The system informs everybody that the phone is now charging
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 115
Android
4.0 International License
Explicit and implicit intents
Explicit Intent
● Starts a specific activity
○ Main activity starts the ViewShoppingCart activity
Implicit Intent
● Asks system to find an activity that can handle this request
○ Clicking Share opens a chooser with a list of apps
Intent: Start app Start main Intent: Shop Start choose Intent: order Start finish
Android activity Android food activity Android order activity
System System System
OrderActivity
Place order
CartActivity CartActivity
View shopping cart View shopping cart
FoodListActivity FoodListActivity FoodListActivity
Choose food items Choose food items Choose food items
MainActivity MainActivity MainActivity MainActivity
What do you want to do? What do you want to do? What do you want to do? What do you want to do?
Ancestral or up navigation
● provided by the app's action bar
● controlled by defining parent-child relationships
between activities in the Android manifest
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 137
Android
4.0 International License
Back navigation
● Back stack preserves history of recently viewed screens
● Back stack contains all the activities that have been launched by the
user in reverse order for the current task
● Each task has its own back stack
● Switching between tasks activates that task's back stack
● Launching an activity from the home screen starts a new task
● Navigate between tasks with the overview or recent tasks screen