Reputation: 13
I am implementing an android application in Xamarin.Android Platform,the application is used to track the distance traveled and route which he traveled. by using background location service and foreground location service for both lower and higher version of the android OS.
I am facing the issue in higher version of the Android Devices(Above 8.0 OS Version) when the user closed the application my foreground service is stopping and am not able track the distance and route. its giving me only start and end points distance with Arial Route.
Please give me any other way to solve my problem without using the Google Or Other Direction APIs.
Upvotes: 1
Views: 390
Reputation: 18861
Cause:
In order to preserve battery, user experience, and system health, background apps receive location updates less frequently when used on a device running Android 8.0. This behavior change affects all apps that receive location updates, including Google Play services.
These changes affect the following APIs:
Solution:
Android 8.0 introduces a new method, called the Context. StartForegroundService (), in the front desk to start a new service. After the system to create the service application have five seconds to call the service startForeground
visible () method to display the new service users notice. If the application is not invoked within this time limit
StartForeground ()
, then the system will stop this application for ANR service and statement.
Intent service = new Intent(TheApplication.getInstance().getApplicationContext(), MyBackgroundService.class);
service.putExtra("startType", 1);
if (Build.VERSION.SDK_INT >= 26) {
TheApplication.getInstance().startForegroundService(service);
} else {
TheApplication.getInstance().startService(service);
}
Upvotes: 0