I am making an application, the location system is similar to uber, which needs to send the location to the firebase every 3 seconds to get the current location live, but when the app is in the background, it stops updating, can you help me?
The code that sends the data to the firebase is this
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Common.mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (Common.mLastLocation != null )
{
if (location_switch.isChecked())
{
final double latitude = Common.mLastLocation.getLatitude();
final double longitude = Common.mLastLocation.getLongitude();
//// PASSAR DADOS PARA O FIREBASE
geoFire.setLocation(FirebaseAuth.getInstance().getCurrentUser().getUid(), new GeoLocation(latitude, longitude), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
// ADICIONA MARCADOR NO MAPA
if (mCurrent != null)
mCurrent.remove();
mCurrent = mMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Voce"));
/// Movimentar camera para sua posicao
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 15.0f));