Ch3 Intent and Service
Ch3 Intent and Service
• Starting an activity
• Starting a service
• Delivering a broadcast
Types of Intent
1 Explicit Intent
2 Implicit Intent
An explicit intent
is Intent where you explicitly define the component
that needs to be called by the Android System.
An explicit intent is one that you can use to launch a
specific app component, such as a particular
activity or service in your app
Intent i= new Intent (this, MainActivity.class);
startActivity(i);
Thus specifying that we want to navigate to
MainActivity.class.
The implicit intent
• The implicit intent is the intent where instead
of defining the exact components, you define
the action that you want to perform for
different activities.
Intent i= new Intent(Intent.ACTION_VIEW);
i=setData(Uri.parse(“http://www.uu.edu.et.com));
startActivity(i);
Thus asking the system to find a suitable componet to
run this URI.
Android Service
• Service is s long running task or process
without any user interaction.
• The android.app.Service is sub class of Context
Wrapper class.
• A Service can essentially take two forms
Started Service
Bound Service
Started Service
• A service is “started” when an application
component starts it by calling startService().
• Once started ,a service can run in the
background indefinitely, even if the
component that stared it is destroyed.
• Started service perform a single operation
and does not return a result to the caller.
Bound Service
• A service is bound when an application
component binds to it by calling bindService().
• A bound service allows components to
interact with the service, send request, get
result and event do so across processes with
interprocess communication(IPC).
• Abound Service runs only as long as another
application component is bound to it.
Con’t
• Multiple component can bind to the service
at once, but when all of them unbind the
service is destroyed.
Thank you