creating Services for location bases application

by Goldmember » Tue, 27 Jan 2009 04:27:46 GMT

Sponsored Links

I am new to android Development.
I have created a location based application which runs in the
Background. I dont get any errors but when i try to check it out using
emulator. I get a message saying that the applicataion has stopped
unexpectedly, Pls try again.
Can some one help me out with this problem.

Service File:

package com.Location.LBS;

import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
import android.widget.Toast;
import android.os.Handler;

class BackgroundServiceTask implements Runnable{

private static final String LOG_TAG="BackgroundService";
private Handler serviceHandler;
private int countDown = 0;
private long interval= 0L;

public BackgroundServiceTask(int countDown, long interval, Handler
this.countDown = countDown;
this.interval = interval;
this.serviceHandler = serviceHandler;

public void run()
Log.d(LOG_TAG,"Counter:"+ countDown);
if(--countDown > 0)
serviceHandler.postDelayed(this, interval);


public class MyService extends Service {

private static final String LOG_TAG ="Background Service";
private Handler serviceHandler = new Handler();
private static final int COUNTDOWN_LIMIT = 10;
private static final long COUNTDOWN_INTERVAL = 3*1000L;

protected void onStart(int startId,Bundle arguments)
super.onStart(null , startId);

GsmCellLocation location;
int cellID, lac;
final String latLongString;

TelephonyManager tm = (TelephonyManager)getSystemService
location = (GsmCellLocation) tm.getCellLocation();

if(location != null)
cellID =location.getCid();
lac = location.getLac();

latLongString="CellID:"+ 2675+"\n Lac:"+8894;

Log.i(getClass().getSimpleName(), "Data From
Location:" +

Toast.makeText(this,"Location:"+latLongString ,
latLongString ="No Location found";

BackgroundServiceTask bst = new BackgroundServiceTask


public void onDestroy()
Log.d(LOG_TAG, "onDestory");

public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;


Broadcast receiver

Other Threads

1. using intent to switch between a simple activity and a tab activity

Kindly help me with the following scenario ,

I have activity A that is tab acitvity ,  I press a certain button and
go to B that is a simple activity , now on clicking a certain button
on B I should be allowed to go back to A but the app crashes , how
ever if i go from B to a normal activity ,it  works perfectly well ,
so the problem is in A being a tab activity , please help


2. Extended Logging Class?

Hi everyone,

Just wondering if anybody has a nice logging class that wraps around the
standard logging class? For example a class that easily allows logging to be
turned on and off, checks for a release etc?



3. Java Keyword This and Button Listeners.

4. Tanya mile XT

5. How can I get the sources for the 1.6 release

6. when to use "aapt add" for shared object files

7. Don't know how to show Video Thumbnails