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. Translucent GLSurfaceView

Hi!
I'm looking at two samples: "Translucent GLSurfaceView" in Graphics /
OpenGL ES and "Translucent" in App / Activity of ApiDemos.
Why the background of" GLSurfaceView" is fully alfa, but in
"Translucent" it's some eclipsed?
I want to make "Translucent" background but in "Translucent
GLSurfaceView" demo.
Thanks!!
--~--~---------~--~----~------------~-------~--~----~

2. Making an advanced layout with moving/scaling

I need a layout where the children are moving and scaled dynamically
when I move my finger (almost like a Listview, but simply offsetting
the childrens' x/y coordinates won't suffice, they need to be scaled
aswell). Right now I'm calling layout(...) on each child every frame.
I think the performance is acceptable, the re-layouting usually takes
between 2-4 ms, which is well below 16 ms (needed for 60 fps
animations). However, is this the best way of doing it? A disadvantage
of this method is that I can't use the childrens drawing caches, which
would make the performance terrible if the children are "advanced"
Views.

Another way of doing it would be by changing the staticTransformation
of each child, every frame. Any thoughts by you guys?
--~--~---------~--~----~------------~-------~--~----~

3. How to license Google Closed Source Apps for device

4. unable to start service --

5. TabLayout strangeness

6. HTC Question

7. Adding new keyboard locale