Binding a service to the Application context

Aryan R

I have a Service that is bound to application context and I use it to do all the long IO operations such as making HttpCalls.

Advantage of binding the service to application context is that none of my activities have to worry about starting and and/ending a service.

However I suspect that this might keep the Application context alive even when the app is closed. Am I right ?

AADProgramming

I suspect that this might keep the Application context alive even when the app is closed.

What is mean by closed here? Does it mean app is pushed into background by pressing HOME by user or it is KILLED by System due to various reasons such as Low memory etc.

Now, to answer your question, getApplicationContext API return the context of the single, global Application object of the current process. Or in other words the lifetime of context is tied to the lifetime of the process of the application rather than the current app component (such as Activity).

Application context live until your application is alive.

Now By assuming the the app being closed means it's Process is killed by Android OS, ideally, the context associated with process too should also be destroyed.

Ref:http://developer.android.com/reference/android/content/Context.html#getApplicationContext()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related