Location tracking while app is in suspended state

ann 0 Reputation points
2024-04-24T09:56:59.74+00:00

Hi,

I am developing a location tracking app for drivers. We need to track locations in particular intervals and send it to server. We are able to track locations when app is active or in background.

How can we get locations for both android & iOS when app is suspended?

It will be great if anybody can help me out.

Thanks in advance.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,900 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,806 Reputation points Microsoft Vendor
    2024-04-25T03:00:05.5433333+00:00

    Hello,

    How can we get locations for both android & iOS when app is suspended?

    This is a keep-alive issue for background services. In this case, the system-level memory reclamation mechanism may reclaim the program's memory while the program is in the background. Because the program's memory is cleared, it cannot continue to run to obtain data.

    Therefore, if you need the program to keep running in the background, you can use some keep-alive mechanism.

    For iOS, Apple officially provides a background running solution for location services, please refer to Configuring your app to use location services and iOS Backgrounding with Tasks.

    For Android, you can use Foreground Service with higher priority to perform location services to avoid memory being recycled when running in the background.

    Since this feature is native to the Android platform, its implementation is no different from what is noted in the Xamarin documentation.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.