Professional Documents
Culture Documents
1. Intents
2. Alarm Managers & Job Schedulers
3. Content Providers
4. Notification Manager (Local Notifications & Push
Notifications)
5. Activity vs Fragments
6. Service
7. Broadcast Receiver
8. Contexts
Intents
• An intent is an abstract description of an operation (action) to be
performed.
• Different activities interact with each other with the help of intent in
Android.
2. You can communicate with components defined by the Android system (a.k.a.
Camera, Services, Contacts, browsers, etc.). - Implicit Intent
3. You can perform an action in future via notifications or after some period of
time. – Pending Intent
4. Intent is also used to pass messages between different activities and services.
Intent Filters?
https://www.tutorialspoint.com/android/android_intents_filters.htm
Types of Intent
Explicit Intent:
• Explicit Android Intent is the Intent in which you explicitly define the
component that needs to be called by Android System.
• When you open an activity from another activity in the same Android app,
you use Explicit Intents.
//SecondActivity
Intent i = getIntent();
MyClass myObject= (MyClass) i.getSerializableExtra("sampleObject");
Gson Library
implementation 'com.google.code.gson:gson:2.8.5'
Gson gson = new Gson();
MyClass vp = new MyClass (5, “Ahmad”);
String myJson = gson.toJson(vp);
intent.putExtra("myjson", myjson);
//SecondActivity
Gson gson = new Gson();
MyClass ob = gson.fromJson(getIntent().getStringExtra("myjson"), MyClass.class);
Implicit Intent
• Implicit Intent is something which is sent from one activity to inbuilt android
activity in android.
• When we work with implicit intents, we generally specify the action which we
want to perform and optionally some data required for that action.
Facilitates inter-application
communication and integration
How implicit Intent Works?
When using implicit intents, given such an arbitrary intent we need to know what to do
with it. This is handled by the process of Intent resolution, which maps an Intent to an
Activity, BroadcastReceiver, or Service (or sometimes two or more activities/receivers)
that can handle it.
The intent resolution mechanism basically revolves around matching an Intent against
all of the <intent-filter> descriptions in the installed application packages.
• There are three pieces of information in the Intent that are used for resolution:
1. the action (multiple predefined actions see docs)
2. Data & type (the data to operate on)
3. category.
• Using this information, a query is done on the PackageManager for a component that
can handle the intent.
• The appropriate component is determined based on the intent information supplied
in the AndroidManifest.xml
Implicit Intent Example
Call a number
Creating Alarm
https://medium.com/@architgupta690/creating-pending-intent-in-android-a-step-by-step-guide-
Alarm Managers & Job Schedulers
Modern apps can perform many of their tasks asynchronously, outside the direct flow of
user interaction. Some examples of these asynchronous tasks are:
1. Updating network resources.
2. Downloading information.
3. Updating background tasks.
4. Scheduling system service calls.
https://www.javatpoint.com/android-alarmmanager
Alarm Managers & Job Schedulers
Alarm Manager (doesn’t work intelligently only at a specific time – out dated)
• The Android AlarmManager holds a CPU wake lock that provides guarantee not to
sleep the phone until broadcast is handled.
https://developer.android.com/topic/performa https://www.javatpoint.com/android-alarmmanager
Job Scheduler
The Android 5.0 Lollipop (API 21) release introduces a job scheduler API via the
JobScheduler class. This API allows to batch jobs when the device has more resources
available.
Conditions:
You can schedule the task to run under specific conditions, such as:
1. Device is charging
2. Device is connected to an unmetered network
3. Device is idle
4. Start before a certain deadline
5. Start within a predefined time window, e.g., within the next hour
6. Start after a minimal delay, e.g., wait a minimum of 10 minutes
https://github.com/firebase/firebase-jobdispatcher-
android#user-content-firebase-jobdispatcher-