creating Services for location bases application

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


Sponsored Links
 i,

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.app.Service;
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
serviceHandler)
{
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);
Log.d(LOG_TAG,"onstart");

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

TelephonyManager tm = (TelephonyManager)getSystemService
(Context.TELEPHONY_SERVICE);
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:" +
latLongString);

Toast.makeText(this,"Location:"+latLongString ,
Toast.LENGTH_SHORT);
}
else
{
latLongString ="No Location found";
}



BackgroundServiceTask bst = new BackgroundServiceTask
(COUNTDOWN_LIMIT, COUNTDOWN_INTERVAL, serviceHandler);
serviceHandler.postDelayed(bst,COUNTDOWN_INTERVAL);
stopSelf();

}

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


@Override
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?

Cheers,
Andy

-- 

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