user1479469
user1479469

Reputation: 45

Background Process for a gps app

I have a button " track my location " which uses GPS and tracks my location successfully. But when i click on the back button , the tracking stops. I want the tracking to go in in the background, even if the user switches over to any other application

I want this function to run in the background

private void centerOnLocation()
{
loc = locman.getLastKnownLocation(provider);
if(loc != null)
{
lat = loc.getLatitude();
    lon = loc.getLongitude();
    templat=lat;
    templon=lon;

    System.out.println("TrackedLat:"+loc);
    System.out.println("temporaryyyyyyyyyyyyyy");
    System.out.println("Templat:"+templat);
    System.out.println("TempLon:"+templon);
    System.out.println("matlat matlon");
    System.out.println("TrackedLon:"+matlat);
    System.out.println("TrackedLon:"+matlon);
Log.i(TAG+"_loc",loc.toString());   
Log.i(TAG, "Lat="+lat+" lon="+lon);
GeoPoint newPoint = new GeoPoint((int)(lat*1e6),(int)(lon*1e6));   
mapControl.animateTo(newPoint);
getSatelliteData();
if(displayOverlay != null){
displayOverlay.putSatStuff(lat, lon, satAccuracy, bearing, altitude,
speed, currentProvider, numberSats);
}

}
  functiontocompare(matlat,matlon,templat,templon);
}

Upvotes: 2

Views: 1562

Answers (1)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132992

I want the tracking to go in in the background, even if the user switches over to any other application

then you need to Integrate a Service for Tracking from background even user switches over to any other application

And for Storing User Loction Use SharedPreferences or Sqlite database.

For Communicate between Service or Activity use Custom BroadcastReciver.

Communication between service and activity 

Upvotes: 2

Related Questions