Android Tutorials


Wednesday, 16 October 2013

Basic Android background Service

Running sample program for background service

Step 1 :
Create sample service class
package com.bishnu.sample.service;

import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService extends Service {
   String tag="TestService";
   public void onCreate() {
       Toast.makeText(this, "Service created...", Toast.LENGTH_LONG).show();      
       Log.i(tag, "Service created...");
   public void onStart(Intent intent, int startId) {      
       super.onStart(intent, startId);  
       Log.i(tag, "Service started...");
   public void onDestroy() {
       Toast.makeText(this, "Service destroyed...", Toast.LENGTH_LONG).show();

   public IBinder onBind(Intent intent) {
       return null;
Step 2 :
Create sample Activity class

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class SampleAction extends Activity {
   protected void onCreate(Bundle savedInstanceState) {      
       TextView view = new TextView(this);      
       view.setText("Service Test");
       Intent i = new Intent();
       i.setClassName( "",
        "" );
       bindService( i, null, Context.BIND_AUTO_CREATE);

Step 3:
Configure AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
   package="" android:versionCode="1"
   <application icon="@drawable/icon" label="@string/app_name">
       <service class=".MyService" name=".MyService">
           <action android:value=""
                   android:name=".MyService" />

      <activity android:name=".SampleAction"
               <action name="android.intent.action.MAIN">
               <category name="android.intent.category.LAUNCHER">

   <uses-sdk minsdkversion="8">



  1. It's very useful: Thank you Bishnu

  2. Its very easy tutorial thank you

  3. android workshop...(training and compitition) by IIT Bombay..

  4. I am Mike Wealth, from Brand Solution (Brands .so). Herewith, I want to offer you an opportunity to own one of our domain names inventory, which can be used as a ready-to-use brand for your company/organization: Tutoroid .com

    For a limited time. we offer you this domain name for only USD 999.
    With this short, 8-letter, 4 syllables domain name, you will have so many advantages, such as:

    It's a .com, the most popular TLD/extension on internet, the first of most people think when they need to search anything on the web. It's much better than .net, .org, .us, etc.

    It's very short, so it's easy to type on any internet browsers, even on mobile devices.

    It's easy to pronounce and to remember.

    It has a very positive vibe for your marketing positioning on customer's mind.

    It will give you an "authority" in your market, as you will have this very elegant name.

    It can be used for your email address.

    You can redirect it to your current website to keep your loyal visitors.

    Please contact me if you're interested in this domain name. I apologize if you're not the right person whom I should contact, would you please forward it to the right one in your company?
    If you don't want to receive any email about this offering, please tell me so I won't bother you anymore.

    I am looking forward to hearing from you.
    Thanks & Regards,

    Mike Wealth,

    www .Brands .so