Why is applicationWillTerminate not being called on the first launch of my app

0 votes

Im building a flutter app and for specific reasons i need write some native code. In detail, my app needs to constantly fetch the user location and then push it to my server. To achieve this, i've come up with a way in which i use geofencing (or Region Monitoring) to restart the app when the it is terminated manually by the user: on applicationWillTerminate() i create a region wide 100m with the user current location in its center and then i start to monitor it. In this way, when the user exists the region the application gets re-launched and the location service is restarted in the background. Everything works fine expect the fact that on the first app launch, right after i've installed it, if i terminate it applicationWillTerminate() does not get called an therefore a region is not created. If i then re-open manually the app and re-terminate it everything works as expected.

Does anyone knows why this is happening?

Mar 14, 2023 in Android by Tejashwini
• 780 points
2,019 views

1 answer to this question.

0 votes

The applicationWillTerminate method is called by the system when the app is about to terminate. However, it's important to note that this method is not called in all cases when the app is terminated. For example, if the app is terminated by the user by swiping it from the App Switcher, or if the system terminates the app due to low memory or other system events, the applicationWillTerminate method will not be called.

In your case, it's possible that the app is being terminated in a way that doesn't trigger the applicationWillTerminate method on the first launch. This could be due to the way the app is installed or due to other system events happening at the same time.

To address this issue, you could consider using other app lifecycle methods such as applicationDidEnterBackground or applicationWillResignActive to create the region when the app is first launched. These methods are called when the app is sent to the background or when the device receives a phone call or other interruption.

Alternatively, you could consider using a different approach to monitor the user's location, such as using a background location service or a push notification triggered by the server to wake up the app when the user's location changes.

It's also worth noting that constantly monitoring the user's location can have a significant impact on battery life, so it's important to implement this functionality carefully and consider the user's privacy and battery concerns.

answered Mar 18, 2023 by vishalini

Related Questions In Android

0 votes
0 answers

Android: why the ICICI iMobile Pay App shows the "rooted/jailbroken" device with my app?

The ICICI iMobile Pay app displays the ...READ MORE

Nov 9, 2022 in Android by Edureka
• 12,690 points
1,087 views
0 votes
1 answer

What is the purpose of setImageResource() in Android?

setImageResource(): Use a resource id to set the ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 13,620 points
1,609 views
0 votes
1 answer

Why YouTube Player API does not work on Android 11?

The Android 11 package visibility limitations prevent ...READ MORE

answered Nov 15, 2022 in Android by Edureka
• 13,620 points
2,084 views
0 votes
0 answers
0 votes
1 answer

URL Scheme for iOS Home App

I think you could try doing it ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,165 views
0 votes
1 answer

swift for windows? xcode on windows? ?

Hi, @Aminegac, If you’re a little more technically ...READ MORE

answered Dec 4, 2020 in Others by Nikita
1,803 views
0 votes
0 answers

How to access and read a file on a USB drive from IOS? (Connected via OTG cable to iPhone)

Can I access a text file on ...READ MORE

Nov 7, 2022 in IOS by Soham
• 9,710 points
581 views
0 votes
0 answers

Tab Bar Appearances before ios 13

I have upgraded to Xcode 13, I'm ...READ MORE

Nov 10, 2022 in Mobile Development by gaurav
• 23,260 points
456 views
0 votes
1 answer

How can I dismiss the on screen keyboard?

To dismiss the on-screen keyboard, you can ...READ MORE

answered Mar 1, 2023 in Android by vishalini
1,665 views
0 votes
1 answer

Opt out or How to stop google bot accounts from my app?

It sounds like you are experiencing an ...READ MORE

answered Mar 18, 2023 in Android by pooja
605 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP