Reputation: 1705
I am still trying to understand the application life cycle of my Android App. I leave my app running in background in the night and in the morning, when I click on the app icon again, the splash screen would appear. From the log file, my Android Application is restarted. However it would still display the old activity from last night. The weird thing is that I could only reproduce this on my phone but not on another developer's phone and I could not find if any app is doing anything special overnight:
Any one has a good link about Application life cycle (not Activity life cycle) on Android?
Upvotes: 4
Views: 2257
Reputation: 15775
Apps are made up of one or more of the components: Activity, Service, BroadcastReceiver and ContentProvider. Each one of these are run as part of your application, all within the same process. Further, each one of these components' entry points (onCreate, onStart, etc.) runs on the main (or UI) thread of your app's process. When your app is put into the background the process is cached and kept ready to go. But, it is up to the framework and kernel to decide limits on this.
So the bottom of line of why your app gets destroyed on one device and not the other is: it depends on the device and on what is running on the device. The Linux kernel running under the Android framework is told what process "limits" are in play for memory resources and the ActivityManager framework component notifies the kernel when a given process is of a certain type. For example, a simple app with just an Activity gets a certain limit and priority (from a process killer perspective, not scheduler). Another app which uses an Activity plus a Service which is marked as a foreground Service gets a different priority, making it "harder" to kill off. The "what is running on the device" part of the answer is just that: what other APKs are installed and active on each device. Your device may be more memory constrained or you could have other apps which have foreground services trying to access the network often, etc. So the Activity/Service/BroadcastReceiver/ContentProvider lifecycle is important as it dictates when your app's overall process is destroyed.
Upvotes: 2