-1

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!

4

2 回答 2

2

根据定义,线程是应用程序的一部分。然后,不可能在应用程序之外有线程。

当您有一个从不创建或使用新线程的应用程序时,您正在运行一个主线程,该线程使用操作系统分配给应用程序的全部 CPU 时间。

既然如此,您的选择是:

1)让您的应用程序在后台运行并连接到它。

2)使用服务方式。

希望这能帮助你理解。

于 2015-03-02T07:11:30.923 回答
1

服务听起来像您想要的(因为即使应用程序消失,它也可以继续运行)。AIDL 的东西更让人痛苦,但这就是你需要做的事情来获得你所要求的行为。

于 2015-03-02T07:08:06.370 回答