Mobile Application Development (Android)

Understand Intents and Service

1.1. Task

In Android the reuse of other application components is a concept known as task. An application can access other Android components to achieve a task. For example, from a component of your application you can trigger another component in the Android system, which manages photos, even if this component is not part of your application. In this component you select a photo and return to your application to use the selected photo.

Such a flow of events is depicted in the following graphic.

1.2. What are intents?

Intents are asynchronous messages which allow application components to request functionality from other Android components. Intents allow you to interact with components from the same applications as well as with components contributed by other applications. For example, an activity can start an external activity for taking a picture.

Intents are objects of the android.content.Intent type. Your code can send them to the Android system defining the components you are targeting. For example, via thestartActivity() method you can define that the intent should be used to start an activity.

An intent can contain data via a Bundle. This data can be used by the receiving component.

1.3. Starting activities

To start an activity, use the method startActivity(intent). This method is defined on the Context object which Activity extends.

xstartactivityviaintent10.png.pagespeed.ic.v0RQxCGOt4

The following code demonstrates how you can start another activity via an intent.

# Start the activity connect to the
# specified class

Intent i = new Intent(this, ActivityTwo.class);
startActivity(i);

1.4. Sub-activities

Activities which are started by other Android activities are called sub-activities. This wording makes it easier to describe which activity is meant.

1.5. Starting services

You can also start services via intents. Use the startService(Intent) method call for that.

2.1. Different types of intents

Android supports explicit and implicit intents.

An application can define the target component directly in the intent (explicit intent) or ask the Android system to evaluate registered components based on the intent data (implicit intents).

2.2. Explicit Intents

Explicit intents explicitly define the component which should be called by the Android system, by using the Java class as identifier.

The following shows how to create an explicit intent and send it to the Android system. If the class specified in the intent represents an activity, the Android system starts it.

Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");

Explicit intents are typically used within on application as the classes in an application are controlled by the application developer.

2.3. Implicit Intents

Implicit intents specify the action which should be performed and optionally data which provides content for the action.

For example, the following tells the Android system to view a webpage. All installed web browsers should be registered to the corresponding intent data via an intent filter.

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.vogella.com"));
startActivity(i);

If an implicit intent is sent to the Android system, it searches for all components which are registered for the specific action and the fitting data type.

If only one component is found, Android starts this component directly. If several components are identified by the Android system, the user will get a selection dialog and can decide which component should be used for the intent.

a) This course is specially designed to provide technical knowledge and skills to cope with the requirement of Android Developer occupations of the Mobile sector. The course will be implemented to ensure at least 80% of total contact hours on practical/hands on skills training or practice and 20% trade/ occupations related theory including OHS and soft modules;

b) The course is designed to enable trainees to acquire a range of technical and vocational, practical, personal and organizational skills valued and utilized both within and beyond the workplace;

c) The course is designed to meet the required competencies of the occupations needed in the labor market in and outside the country;


Download This Course Outline

  • Android Overview & Quick Start

  • Main Building Blocks

  • Java Basics

    • Create hello world application in java
      Viewing Completed Lesson
    • Data types in Java
      Viewing Completed Lesson
    • Methods in java
      Viewing Completed Lesson
    • See the list of number in display
      Viewing Completed Lesson
    • Understand basic anatomy of a java program for android application
      Viewing Completed Lesson
    • Understand conditional statement, looping
      Viewing Completed Lesson
    • Work with java variables: integer, string, double
      Viewing Completed Lesson
  • OOP Basics

    • Create a class with the collection of another class in its field
      Viewing Completed Lesson
    • Define association relationship
      Viewing Completed Lesson
    • Define static class and method from real life example
      Viewing Completed Lesson
    • Encapsulate your data and its functionality
      Viewing Completed Lesson
    • Keep some field, property, method inside a class
      Viewing Completed Lesson
    • Understand the essence of inheritance relationship
      Viewing Completed Lesson
  • Android User Interface

    • Design a simple activity layout for some basic user operation
      Viewing Completed Lesson
    • Design UI with Fragments and ActionBar
      Viewing Completed Lesson
    • Familiar with UI Widgets
      Viewing Completed Lesson
    • Understand View and Layout
      Viewing Completed Lesson
    • What is activity life cycle
      Viewing Completed Lesson
  • SQLite Database

    • Create a table in SQLite
      Viewing Completed Lesson
    • Doing CRUD operation in database
      Viewing Completed Lesson
    • How to manage SQLite database
      Viewing Completed Lesson
    • Overview on SQLite and Database design
      Viewing Completed Lesson
    • Save and select data from database using Android Application
      Viewing Completed Lesson
  • Broadcast receivers

    • How to start a service by using broadcast receiver
      Viewing Completed Lesson
    • Receive an event
      Viewing Completed Lesson
    • Start a service
      Viewing Completed Lesson
    • Understand event receiving.
      Viewing Completed Lesson
  • Services

    • Generate notification using service
      Viewing Completed Lesson
    • How to play music as a background service
      Viewing Completed Lesson
    • Implement different types of service
      Viewing Completed Lesson
    • Lifecycle of services
      Viewing Completed Lesson
  • Content Providers

    • How to create content provider
      Viewing Completed Lesson
    • Pass data from one process to another
      Viewing Completed Lesson
    • Simplify database operation
      Viewing Completed Lesson
    • Use content provider
      Viewing Completed Lesson
  • APIs

    • Access call state
      Viewing Completed Lesson
    • Access phone call state
      Viewing Completed Lesson
    • Drawing routes on Map
      Viewing Completed Lesson
    • Finding users location
      Viewing Completed Lesson
    • Introduction to sensor
      Viewing Completed Lesson
    • Maps issues
      Viewing Completed Lesson
    • Retrieve telephony network information
      Viewing Completed Lesson
    • Understand Location API
      Viewing Completed Lesson
    • Working with Map API
      Viewing Completed Lesson