Android: Application onCreate called every time app goes to background
Asked Answered
U

1

8

I've a strange behavior with an android app when it runs on a S3 with android 4.3: every time app goes to background (pressing back button), when it's resumed, it calls the onCreate() method of Application class.

Reading the Android documentation, Application onCreate() should be called the first time app runs, when app is destroyed or if the device has low memory, but seems it's not my case (I added a log into onLowMemory())

So my question is: in which conditions Application onCreate() method is called? Does it depends on device and/or android versions?

Uboat answered 26/6, 2014 at 17:58 Comment(5)
does onDestroy run for the given activities ? do you call finish in any onPause methods ?Kalikow
Hi Lena, when user press back device button, the activity that is running at the moment calls onPause(), onStop() and then onDestroy(). There isn't a finish call inside the methods above-mentioned. What is curious is that I've no problem with other devices like S4, S5 etc.Uboat
if onDestroy is called, then onCreate must be called againKalikow
onDestroy() should shut down the activity class, but not the Application class.Uboat
Do you have the developer setting "don't keep activities" enabled? If so, every time you leave an Activity, Android will destroy that Activity. If there are no active activities in an OS process, Android will kill off that OS process. Different manufacturers and different devices will behave differently as to how aggressively they kill off non-active OS processes. It sounds like this device has a very agressive algorithm (which could be because it has a small memory footprint, or is trying to save battery, etc.)Ninfaningal
N
0

See my comment, but to answer your question:

in which conditions Application onCreate() method is called? Does it depends on device and/or android versions?

Application.onCreate() is called when Android creates the Application instance for your app. This happens when Android creates an OS process for your app. This method is called only once and it won't be called again unless your application process is killed and recreated by Android.

Ninfaningal answered 19/6, 2023 at 18:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.