The document provides an overview of key Android app development concepts including activities, services, broadcast receivers, content providers, the activity lifecycle, asynchronous tasks, SQLite database usage, and Google Maps integration. It discusses how activities represent screens, services run in the background, broadcast receivers respond to system broadcasts, and content providers share data between apps. It also covers the activity lifecycle, asynchronous tasks, SQLite database implementation using SQLiteOpenHelper, and steps to add a map with markers to an app using the Google Maps Android API.
2. This work is licensed under a Creative
Commons Attribution-NonCommercial 4.0
International License.
“ First, solve the problem. Then, write the code. ” -
John Johnson
3. Hello!
I am S MAHBUB UZ ZAMAN
You can me at mahbub.ninja
5. “
Activity
An activity represents a single screen with a user interface.
Service
A service is a component that runs in the background
to perform long-running operations or to perform
work for remote processes. A service does not provide
a user interface.
Content provider
Enable applications to share data
Broadcast receiver
A Broadcast receiver is a component that
responds to system-wide Broadcast
announcements.
◦ play music
◦ fetch data over network
Database CP
APP 1
APP 2
APP 3
◦ screen has turned off
◦ the battery is low
◦ a picture was captured
◦ Apps can also initiate broadcasts
11. Started or Unbounded
Service
This service is called by
an app component and
run in the background
even if the caller
component is destroyed.
Bounded Service
This service is called by
an app component, runs
in the background and it
offers communication or
interaction between the
service and the
component that
launched it. But this type
of service is destroyed
when all the
components that are
bound to it are closed
Types Of Service
16. .
Async Task
◦ AsyncTask enables proper and easy use of the UI thread. This class allows
to perform background operations and publish results on the UI thread
◦ An asynchronous task is defined by 3 generic types, called Params,
Progress and Result
◦ and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and
onPostExecute.
new DownloadFilesTask().execute(url1, url2, url3);
17. private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) {
int count = urls.length;
long totalSize = 0;
for (int i = 0; i < count; i++) {
totalSize += Downloader.downloadFile(urls[i]);
publishProgress((int) ((i / (float) count) * 100));
// Escape early if cancel() is called
if (isCancelled()) break;
}
return totalSize;
}
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
protected void onPostExecute(Long result) {
showDialog("Downloaded " + result + " bytes");
}
}
Sample Code
18. The three types used by an asynchronous task are the following:
1. Params, the type of the parameters sent to the task upon
execution.
2. Progress, the type of the progress units published during the
background computation.
3. Result, the type of the result of the background computation.
Not all types are always used by an asynchronous task. To mark a
type as unused, simply use the type Void:
AsyncTask's generic types
private class MyTask extends AsyncTask<Void, Void, Void> {}
19. When an asynchronous task is executed, the task goes through 4 steps:
1. onPreExecute(), invoked on the UI thread before the task is executed. This step is
normally used to setup the task, for instance by showing a progress bar in the user
interface.
2. doInBackground(Params...), invoked on the background thread immediately after
onPreExecute() finishes executing. This step is used to perform background
computation that can take a long time. The parameters of the asynchronous task are
passed to this step. The result of the computation must be returned by this step and
will be passed back to the last step. This step can also use publishProgress
(Progress...) to publish one or more units of progress. These values are published on
the UI thread, in the onProgressUpdate(Progress...) step.
3. onProgressUpdate(Progress...), invoked on the UI thread after a call to
publishProgress(Progress...). The timing of the execution is undefined. This method is
used to display any form of progress in the user interface while the background
computation is still executing. For instance, it can be used to animate a progress bar
or show logs in a text field.
4. onPostExecute(Result), invoked on the UI thread after the background computation
finishes. The result of the background computation is passed to this step as a
parameter.
The 4 steps
21. Service
A service is simply a
component that can
run in the
background even
when the user is not
interacting with
your application.
Thus, you should
create a service
only if that is what
you need
Thread
If you need to
perform work
outside your main
thread, but only
while the user is
interacting with
your application,
then you should
probably instead
create a new thread
and not a service