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. ?? HttpHostConnectException: Connection to http://127.0.0.1 refused ??

I am a student in Computer Science in Morocco.
I'm sorry about my english, but I have some questions about android.
I want to port android to dev2410
(
http://www.pragmatec.net/catalog/product_info.php?products_id=56&osCsid=2e82f46be064a4ab8b3a276090cafd77
).
I already tested the kernel with linux rootfs then it works. My last
step is to port the "android userspace".
I use NFSRoot when I boot, the system hangs after mounting the nfs
rootfs "Unable to open initial console". When I add the file "/
dev/console", the message disappears but the system hangs again after
"Freeing init memory: 208K".
Question 1 - do I have to manually populate /dev directory.
Question 2 - When I execute android init (from other rootfs), I get a
message like "Illegal Instruction" even I have compiled the kernel
with EABI. Why?

Thanks
See you!

--~--~---------~--~----~------------~-------~--~----~

2. Is there a way to determine which phone I'm running on?

Is there a way to get the phone type?  For example, can I determine if
the phone is a G1, or myTouch, etc?
--~--~---------~--~----~------------~-------~--~----~

3. For a project demonstration, any way to clone device screen on a monitor?

4. Accessing the Calendar

5. Text with different FILL and STROKE colours

6. Disable wlan interface after disconnect in WifiStateTracker

7. OpenLoopz Video Available