Problem in GPS while running in timer

by Nemat » Wed, 11 Nov 2009 14:01:40 GMT


Sponsored Links
 i frinds......

I am presently working on GPS.I have to start GPS periodically.I mean
I want GPS to start after a particular intervel,get Location value and
then stop taking location updates.For this,I m calling
requestLocationUpdates( , , ) method in a timer.Then in
onLocationChanged(), I stop taking location by using removeUpdates
().Then after particular intervel ,it again start taking values,then
when location changes ,it stops, and so on......

Here is my code:
TimerTask IntervelTimer = new TimerTask()
{
public void run()
{
Log.d
("startLocationUpdate","startLocationUpdate");
startLocationUpdate();

}
};
Timer timer2 = new Timer();


try{
timer2.schedule(IntervelTimer, 1*60 * 1000, 1*60 * 1000);
}
catch(Exception e)
{
Log.e("Error",e.toString());
}

public void startLocationUpdate()
{
System.out.println("startLocationUpdate()");
if(locationListener==null)
{
Looper.prepare();

locationListener = new MyLocationListener();
try{
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);
}
catch(Exception e)
{
Log.e("error",e.toString());
}
Looper.loop();
Looper.myLooper().quit();
}
}

private class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc) {
System.out.println("GetLocation");
if (loc != null) {
StoreGPSlocation(String.valueOf
(loc.getLatitude()),String.valueOf(loc.getLongitude()));
stopLocationUpdate();
}
}

public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}

public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}

public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
}

public void stopLocationUpdate()
{
LocationManager lm = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
if (lm != null)

{
if (locationListener != null)

{

lm.removeUpdates(locationListener);
locationListener= null;

}



lm = null;

}



}

Now the problem is:It starts fine for the first tim



Problem in GPS while running in timer

by Nemat » Wed, 11 Nov 2009 14:01:46 GMT


 i frinds......

I am presently working on GPS.I have to start GPS periodically.I mean
I want GPS to start after a particular intervel,get Location value and
then stop taking location updates.For this,I m calling
requestLocationUpdates( , , ) method in a timer.Then in
onLocationChanged(), I stop taking location by using removeUpdates
().Then after particular intervel ,it again start taking values,then
when location changes ,it stops, and so on......

Here is my code:
TimerTask IntervelTimer = new TimerTask()
{
public void run()
{
Log.d
("startLocationUpdate","startLocationUpdate");
startLocationUpdate();

}
};
Timer timer2 = new Timer();


try{
timer2.schedule(IntervelTimer, 1*60 * 1000, 1*60 * 1000);
}
catch(Exception e)
{
Log.e("Error",e.toString());
}

public void startLocationUpdate()
{
System.out.println("startLocationUpdate()");
if(locationListener==null)
{
Looper.prepare();

locationListener = new MyLocationListener();
try{
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);
}
catch(Exception e)
{
Log.e("error",e.toString());
}
Looper.loop();
Looper.myLooper().quit();
}
}

private class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc) {
System.out.println("GetLocation");
if (loc != null) {
StoreGPSlocation(String.valueOf
(loc.getLatitude()),String.valueOf(loc.getLongitude()));
stopLocationUpdate();
}
}

public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}

public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}

public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
}

public void stopLocationUpdate()
{
LocationManager lm = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
if (lm != null)

{
if (locationListener != null)

{

lm.removeUpdates(locationListener);
locationListener= null;

}



lm = null;

}



}

Now the problem is:It starts fine for the first tim


Sponsored Links


Problem in GPS while running in timer

by 褰偟 » Mon, 16 Nov 2009 12:47:25 GMT


 i, Nemat

I think your problem is that you call requestLocationUpdates in the
TimerTask thread.

As the
document<http://androidappdocs.appspot.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String,
long, float, android.location.LocationListener)> says, The calling thread
must be a
Looper<file:///E:/SDK/android-sdk-windows-1.6_r1/docs/reference/android/os/Looper.html>thread
such as the main thread of the calling Activity.

2009/11/11 Nemat <nemate...@gmail.com>

>



Other Threads

1. how to debug an application which starts with file manager application

Hello to all.

I want to debug an PDF viewer application in eclipse.

The file cannot be directly opened using the application.

The application starts only using selecting a file from file manager
and then selecting the PDF viewer application from file manager. If I
directly start the application in debug mode, I cannot open the file.

How can I debug it??

Can you please tell me??

-- 

2. Para suhu di Forsel

Jiaaahhh...
Forsel jaman baheula nih...
Yang sekarang mah modelnya bos AH sama suhu ntil swimsuit edition :p

@yopiesuryadi
www.jeruknipis.com/forum

-----Original Message-----
From: "Muchsin T. Assegaf" <mtouriq.andr...@gmail.com>
Date: Mon, 3 May 2010 05:08:42 
To: Milis Android<id-android@googlegroups.com>
Subject: [id-android] Para suhu di Forsel

Barusan beli Forsel, eeehhhh... Ada penampakan para suhu disana :))

---
MooKsMobile
Twit/Y!/Gtalk: @mtouriq

-- 
"Indonesian Android Community [id-android]" 

3. Notification icon from a different package

4. Android User dr Jogja

5. Some users are not finding our app in Android Market

6. how to draw objects in openGl with delay

7. widget doesn't fresh on verizon droid, but works fine on HTC eris.