I am trying to do specific task in a separate thread in android using Thread Pool executor with the Max thread size of 5 making sure there can be five parallel task would be run at a time. But problem with this approach is When I close my application the thread will also be killed. I want this to run out of application scope. I could have opted for service with the AIDL . But problem with this is I need to keep on bind and unbind to the service and I need to parcel the object before I need to send it. Also when the task is completed i need to communicate back to the calling application. This I could any how achieve using Broadcast. I was wondering If I can make a thread run in a separate process or I need to go with AIDL only ? Please help me understand!
Asked
Active
Viewed 478 times
2 Answers
2
A thread is, by definition, part of an application. Then, it's not possible to have a thread outside an app.
When you have an app that never creates nor uses new threads, you're running a main thread, that uses the full CPU time assigned by the OS to the app.
Since this, your options are:
1) To leave your app running in background and connect to it.
2) To use the service way.
Hope this help you to understand.

Btc Sources
- 1,912
- 2
- 30
- 58
-
Thanks BTC Sources. It is clear to me , i thought If I can make a thread to run in a separate process rather than from one which is getting called will do the job. But I had little idea in this regards. Thanks for clearing my doubt! – Nitin Mesta Mar 02 '15 at 07:19
-
1Just to give some references about it: http://developer.android.com/guide/components/tasks-and-back-stack.html. Here you have how apps are based on activities. I could put the services documentation, but u seem to know it well already ;) – Btc Sources Mar 02 '15 at 07:27
1
A service sounds like what you want (since it can keep running even if the application goes away). It's more of a pain with the AIDL stuff, but that's what you need to do to get the behaviour you're asking for.

Buddy
- 10,874
- 5
- 41
- 58