Mobile Application Development (Android)

Understand Content Providers, Broadcast receivers and Application context

A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.

content

 

sometimes it is required to share data across applications. This is where content providers become very useful.

Content providers let you centralize content in one place and have many different applications access it as needed. A content provider behaves very much like a database where you can query it, edit its content, as well as add or delete content using insert(), update(), delete(), and query() methods. In most cases this data is stored in an SQlite database.

A content provider is implemented as a subclass of ContentProvider class and must implement a standard set of APIs that enable other applications to perform transactions.

public class My Application extends  ContentProvider {

}

Create Content Provider

This involves number of simple steps to create your own content provider.

  • First of all you need to create a Content Provider class that extends theContentProviderbaseclass.
  • Second, you need to define your content provider URI address which will be used to access the content.
  • Next you will need to create your own database to keep the content. Usually, Android uses SQLite database and framework needs to overrideonCreate() method which will use SQLite Open Helper method to create or open the provider’s database. When your application is launched, theonCreate() handler of each of its Content Providers is called on the main application thread.
  • Next you will have to implement Content Provider queries to perform different database specific operations.
  • Finally register your Content Provider in your activity file using <provider> tag.

Here is the list of methods which you need to override in Content Provider class to have your Content Provider working:

content1

  • onCreate() This method is called when the provider is started.
  • query() This method receives a request from a client. The result is returned as a Cursor object.
  • insert()This method inserts a new record into the content provider.
  • delete() This method deletes an existing record from the content provider.
  • update() This method updates an existing record from the content provider.
  • getType() This method returns the MIME type of the data at the given URI.
 

Creating the Broadcast Receiver

A broadcast receiver is implemented as a subclass of BroadcastReceiverclass and overriding the onReceive() method where each message is received as a Intent object parameter.

public class MyReceiver extends BroadcastReceiver {
   @Override
   public void onReceive(Context context, Intent intent) {
      Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
   }
}
 

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