Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, does foreground service keep app alive?

Will Android kill public class App extends Application if there is a foreground service running?

I am not sure if it's even important... If I have a reference from that service to a object instantiated in Activity or App and that Activity/App gets killed, will reference from the service still be valid?

Last question is... What happens with static fields if app associated with the class containing the static fields gets killed?

like image 283
Worly Avatar asked Oct 20 '25 17:10

Worly


1 Answers

Will Android kill public class App extends Application if there is a foreground service running?

Classes are not "killed" in Android. Processes are terminated. An Application instance is created when your process is created, and it remains around until the process is terminated.

So long as the foreground service is running, it's process is alive (by definition), and its Application will remain around.

What happens with static fields if app associated with the class containing the static fields gets killed?

Again, classes are not "killed" in Android. Processes are terminated. When your process is terminated, everything in memory goes away, including static fields and their references.

like image 71
CommonsWare Avatar answered Oct 23 '25 05:10

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!