SlideShare a Scribd company logo
M D . M U J A H I D I S L A M
A P P S D E V E L O P E R
U N I T E D F I N A N C E
Android Application Development
1
Android Components
There are four different types of app components:
1. Activities.
2. Services.
3. Broadcast receivers.
4. Content providers.
2
Activity
An activity is the entry point for interacting with the
user. It represents a single screen with a user
interface.
Keeping track of what the user currently cares about
(what is on screen) to ensure that the system keeps
running the process that is hosting the activity.
Knowing that previously used processes contain
things the user may return to (stopped activities),
and thus more highly prioritize keeping those
processes around.
3
Activity
Helping the app handle having its process killed so
the user can return to activities with their previous
state restored.
Providing a way for apps to implement user flows
between each other, and for the system to coordinate
these flows.
4
Service
5
A service is a general-purpose entry point for
keeping an app running in the background for all
kinds of reasons.
 It 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.
Broadcast Receiver
6
 A broadcast receiver is a component that enables
the system to deliver events to the app outside of a
regular user flow, allowing the app to respond to
system-wide broadcast announcements.
 Broadcast receivers are another well-defined entry
into the app, the system can deliver broadcasts even
to apps that aren't currently running.
Content providers
7
A content provider manages a shared set of app data
that you can store in the file system, in a SQLite
database, on the web, or on any other persistent
storage location that your app can access.
Through the content provider, other apps can query
or modify the data if the content provider allows it.
The manifest file
8
Identifies any user permissions the app requires,
such as Internet access or read-access to the user's
contacts.
Declares the minimum API Level required by the
app, based on which APIs the app uses.
Declares hardware and software features used or
required by the app, such as a camera, bluetooth
services, or a multitouch screen.
Declares API libraries the app needs to be linked
against (other than the Android framework APIs),
such as the Google Maps library.
The manifest file
9
You must declare all app components using the
following elements:
1. <activity> elements for activities.
2. <service> elements for services.
3. <receiver> elements for broadcast receivers.
4. <provider> elements for content providers.
Activity Life Cycle
10
Navigating between activities
11
Depending on whether your activity wants a result
back from the new activity it’s about to start, you
start the new activity using either the startActivity()
or the startActivityForResult() method.
The Intent object specifies either the exact activity
you want to start or describes the type of action you
want to perform (and the system selects the
appropriate activity for you, which can even be from
a different application).
An Intent object can also carry small amounts of
data to be used by the activity that is started.
Navigating between activities
12
Intent intent = new Intent(this, SignInActivity.class);
startActivity(intent);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, recipientArray);
startActivity(intent);
startActivityForResult(new Intent(Intent.ACTION_PICK,new Uri("content://contacts")),
PICK_CONTACT_REQUEST);
Saving activity state
13
static final String STATE_SCORE = "playerScore";
static final String STATE_LEVEL = "playerLevel";
...
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save the user's current game state
savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);
// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}
Restoring activity state
14
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // Always call the superclass first
// Check whether we're recreating a previously destroyed instance
if (savedInstanceState != null) {
// Restore value of members from saved state
mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
} else {
// Probably initialize members with default values for a new instance
}
...
}
Restoring activity state
15
public void onRestoreInstanceState(Bundle savedInstanceState) {
// Always call the superclass so it can restore the view hierarchy
super.onRestoreInstanceState(savedInstanceState);
// Restore state members from saved instance
mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
}
Sending data between activities
16
Parcelable and Bundle objects are intended to be used
across process boundaries such as with IPC/Binder
transactions, between activities with intents, and to
store transient state across configuration changes.
Intent intent = new Intent(this, MyActivity.class);
intent.putExtra("media_id", "a1b2c3");
...
startActivity(intent);
Sending data between processes
17
Sending data between processes is similar to doing
so between activities. However, when sending
between processes, we recommend that you do not
use custom parcelables.
 If you send a custom Parcelable object from one app
to another, you need to be certain that the exact
same version of the custom class is present on both
the sending and receiving apps. Typically this could
be a common library used across both apps.
Processes and Application Lifecycle
18
In most cases, every Android application runs in its own
Linux process.
This process is created for the application when some of
its code needs to be run, and will remain running until it
is no longer needed and the system needs to reclaim its
memory for use by other applications.
An unusual and fundamental feature of Android is that
an application process's lifetime is not directly controlled
by the application itself. Instead, it is determined by the
system through a combination of the parts of the
application that the system knows are running, how
important these things are to the user, and how much
overall memory is available in the system.
Processes and Application Lifecycle
19
1. Foreground Process
2. A Visible Process
3. A Service Process
4. A Cached Process
Foreground Process
20
A foreground process is one that is required for what the
user is currently doing. Various application components
can cause its containing process to be considered
foreground in different ways. A process is considered to be
in the foreground if any of the following conditions hold:
It is running an Activity at the top of the screen that the
user is interacting with (its onResume() method has been
called).
It has a BroadcastReceiver that is currently running (its
BroadcastReceiver.onReceive() method is executing).
It has a Service that is currently executing code in one of
its callbacks (Service.onCreate(), Service.onStart(), or
Service.onDestroy()).
Visible Process
21
A visible process is doing work that the user is
currently aware of, so killing it would have a noticeable
negative impact on the user experience. A process is
considered visible in the following conditions:
It is running an Activity that is visible to the user on-
screen but not in the foreground (its onPause()
method has been called).
It has a Service that is running as a foreground
service, through Service.startForeground()
A Service Process
22
A service process is one holding a Service that has been
started with the startService() method. Though these
processes are not directly visible to the user, they are
generally doing things that the user cares about (such
as background network data upload or download), so
the system will always keep such processes running
unless there is not enough memory to retain all
foreground and visible processes.
A Cached Process
23
A cached process is one that is not currently needed,
so the system is free to kill it as desired when memory
is needed elsewhere. In a normally behaving system,
these are the only processes involved in memory
management: a well running system will have multiple
cached processes always available (for more efficient
switching between applications) and regularly kill the
oldest ones as needed.
Question
24

More Related Content

Similar to Android application development

Unit2
Unit2Unit2
04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)TECOS
 
Android Development Basics
Android Development BasicsAndroid Development Basics
Android Development Basics
Prajakta Dharmpurikar
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8Utkarsh Mankad
 
Android Training (android fundamental)
Android Training (android fundamental)Android Training (android fundamental)
Android Training (android fundamental)
Khaled Anaqwa
 
Android beginners David
Android beginners DavidAndroid beginners David
Android beginners David
Arun David Johnson R
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
Headerlabs Infotech Pvt. Ltd.
 
Android101
Android101Android101
Android101
David Marques
 
Android 101 Session @thejunction32
Android 101 Session @thejunction32Android 101 Session @thejunction32
Android 101 Session @thejunction32
Eden Shochat
 
Nativa Android Applications development
Nativa Android Applications developmentNativa Android Applications development
Nativa Android Applications development
Alfredo Morresi
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
Chandrakant Divate
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Password security system for websites
Password security system for websitesPassword security system for websites
Password security system for websites
Mike Taylor
 
Android Security
Android SecurityAndroid Security
Android Security
Suminda Gunawardhana
 
A Framework for Providing Selective Permissions to Android Applications
A Framework for Providing Selective Permissions to Android ApplicationsA Framework for Providing Selective Permissions to Android Applications
A Framework for Providing Selective Permissions to Android Applications
IOSR Journals
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
Kumar
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
Aly Abdelkareem
 
OS in mobile devices [Android]
OS in mobile devices [Android]OS in mobile devices [Android]
OS in mobile devices [Android]
Yatharth Aggarwal
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
faiz324545
 

Similar to Android application development (20)

Unit2
Unit2Unit2
Unit2
 
Android
AndroidAndroid
Android
 
04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)
 
Android Development Basics
Android Development BasicsAndroid Development Basics
Android Development Basics
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8
 
Android Training (android fundamental)
Android Training (android fundamental)Android Training (android fundamental)
Android Training (android fundamental)
 
Android beginners David
Android beginners DavidAndroid beginners David
Android beginners David
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Android101
Android101Android101
Android101
 
Android 101 Session @thejunction32
Android 101 Session @thejunction32Android 101 Session @thejunction32
Android 101 Session @thejunction32
 
Nativa Android Applications development
Nativa Android Applications developmentNativa Android Applications development
Nativa Android Applications development
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Password security system for websites
Password security system for websitesPassword security system for websites
Password security system for websites
 
Android Security
Android SecurityAndroid Security
Android Security
 
A Framework for Providing Selective Permissions to Android Applications
A Framework for Providing Selective Permissions to Android ApplicationsA Framework for Providing Selective Permissions to Android Applications
A Framework for Providing Selective Permissions to Android Applications
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
OS in mobile devices [Android]
OS in mobile devices [Android]OS in mobile devices [Android]
OS in mobile devices [Android]
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 

Recently uploaded

RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 

Recently uploaded (20)

RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 

Android application development

  • 1. M D . M U J A H I D I S L A M A P P S D E V E L O P E R U N I T E D F I N A N C E Android Application Development 1
  • 2. Android Components There are four different types of app components: 1. Activities. 2. Services. 3. Broadcast receivers. 4. Content providers. 2
  • 3. Activity An activity is the entry point for interacting with the user. It represents a single screen with a user interface. Keeping track of what the user currently cares about (what is on screen) to ensure that the system keeps running the process that is hosting the activity. Knowing that previously used processes contain things the user may return to (stopped activities), and thus more highly prioritize keeping those processes around. 3
  • 4. Activity Helping the app handle having its process killed so the user can return to activities with their previous state restored. Providing a way for apps to implement user flows between each other, and for the system to coordinate these flows. 4
  • 5. Service 5 A service is a general-purpose entry point for keeping an app running in the background for all kinds of reasons.  It 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.
  • 6. Broadcast Receiver 6  A broadcast receiver is a component that enables the system to deliver events to the app outside of a regular user flow, allowing the app to respond to system-wide broadcast announcements.  Broadcast receivers are another well-defined entry into the app, the system can deliver broadcasts even to apps that aren't currently running.
  • 7. Content providers 7 A content provider manages a shared set of app data that you can store in the file system, in a SQLite database, on the web, or on any other persistent storage location that your app can access. Through the content provider, other apps can query or modify the data if the content provider allows it.
  • 8. The manifest file 8 Identifies any user permissions the app requires, such as Internet access or read-access to the user's contacts. Declares the minimum API Level required by the app, based on which APIs the app uses. Declares hardware and software features used or required by the app, such as a camera, bluetooth services, or a multitouch screen. Declares API libraries the app needs to be linked against (other than the Android framework APIs), such as the Google Maps library.
  • 9. The manifest file 9 You must declare all app components using the following elements: 1. <activity> elements for activities. 2. <service> elements for services. 3. <receiver> elements for broadcast receivers. 4. <provider> elements for content providers.
  • 11. Navigating between activities 11 Depending on whether your activity wants a result back from the new activity it’s about to start, you start the new activity using either the startActivity() or the startActivityForResult() method. The Intent object specifies either the exact activity you want to start or describes the type of action you want to perform (and the system selects the appropriate activity for you, which can even be from a different application). An Intent object can also carry small amounts of data to be used by the activity that is started.
  • 12. Navigating between activities 12 Intent intent = new Intent(this, SignInActivity.class); startActivity(intent); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, recipientArray); startActivity(intent); startActivityForResult(new Intent(Intent.ACTION_PICK,new Uri("content://contacts")), PICK_CONTACT_REQUEST);
  • 13. Saving activity state 13 static final String STATE_SCORE = "playerScore"; static final String STATE_LEVEL = "playerLevel"; ... @Override public void onSaveInstanceState(Bundle savedInstanceState) { // Save the user's current game state savedInstanceState.putInt(STATE_SCORE, mCurrentScore); savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel); // Always call the superclass so it can save the view hierarchy state super.onSaveInstanceState(savedInstanceState); }
  • 14. Restoring activity state 14 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Always call the superclass first // Check whether we're recreating a previously destroyed instance if (savedInstanceState != null) { // Restore value of members from saved state mCurrentScore = savedInstanceState.getInt(STATE_SCORE); mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL); } else { // Probably initialize members with default values for a new instance } ... }
  • 15. Restoring activity state 15 public void onRestoreInstanceState(Bundle savedInstanceState) { // Always call the superclass so it can restore the view hierarchy super.onRestoreInstanceState(savedInstanceState); // Restore state members from saved instance mCurrentScore = savedInstanceState.getInt(STATE_SCORE); mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL); }
  • 16. Sending data between activities 16 Parcelable and Bundle objects are intended to be used across process boundaries such as with IPC/Binder transactions, between activities with intents, and to store transient state across configuration changes. Intent intent = new Intent(this, MyActivity.class); intent.putExtra("media_id", "a1b2c3"); ... startActivity(intent);
  • 17. Sending data between processes 17 Sending data between processes is similar to doing so between activities. However, when sending between processes, we recommend that you do not use custom parcelables.  If you send a custom Parcelable object from one app to another, you need to be certain that the exact same version of the custom class is present on both the sending and receiving apps. Typically this could be a common library used across both apps.
  • 18. Processes and Application Lifecycle 18 In most cases, every Android application runs in its own Linux process. This process is created for the application when some of its code needs to be run, and will remain running until it is no longer needed and the system needs to reclaim its memory for use by other applications. An unusual and fundamental feature of Android is that an application process's lifetime is not directly controlled by the application itself. Instead, it is determined by the system through a combination of the parts of the application that the system knows are running, how important these things are to the user, and how much overall memory is available in the system.
  • 19. Processes and Application Lifecycle 19 1. Foreground Process 2. A Visible Process 3. A Service Process 4. A Cached Process
  • 20. Foreground Process 20 A foreground process is one that is required for what the user is currently doing. Various application components can cause its containing process to be considered foreground in different ways. A process is considered to be in the foreground if any of the following conditions hold: It is running an Activity at the top of the screen that the user is interacting with (its onResume() method has been called). It has a BroadcastReceiver that is currently running (its BroadcastReceiver.onReceive() method is executing). It has a Service that is currently executing code in one of its callbacks (Service.onCreate(), Service.onStart(), or Service.onDestroy()).
  • 21. Visible Process 21 A visible process is doing work that the user is currently aware of, so killing it would have a noticeable negative impact on the user experience. A process is considered visible in the following conditions: It is running an Activity that is visible to the user on- screen but not in the foreground (its onPause() method has been called). It has a Service that is running as a foreground service, through Service.startForeground()
  • 22. A Service Process 22 A service process is one holding a Service that has been started with the startService() method. Though these processes are not directly visible to the user, they are generally doing things that the user cares about (such as background network data upload or download), so the system will always keep such processes running unless there is not enough memory to retain all foreground and visible processes.
  • 23. A Cached Process 23 A cached process is one that is not currently needed, so the system is free to kill it as desired when memory is needed elsewhere. In a normally behaving system, these are the only processes involved in memory management: a well running system will have multiple cached processes always available (for more efficient switching between applications) and regularly kill the oldest ones as needed.