我想知道android中活动和服务之间的线程流

时间:2014-11-06 13:24:02

标签: android multithreading performance android-activity service

当我从活动开始服务时, 这是主线吗?

我想知道为什么我的系统太慢,如果我激活服务。 所以我想服务可能会使用主线程。

[服务] - 主要工作 - onStartCommand

for(int i = 0; i < hp.length; i++){
   if(i%10 == 0 && i != 0){
    Log.i(TAG, "total data : "+hp.length);
   }
}                   
stopSelf();

我是否在服务流程中使用另一个线程? 给我一个建议。

Thx:)

1 个答案:

答案 0 :(得分:2)

如此处所述https://developer.android.com/guide/components/services.html

Service This is the base class for all services. When you extend this class, 创建新线程以执行所有服务工作非常重要 , because the service 使用应用程序的主线程 {{ 1}}

<强> IntentService , by default, which could slow the performance of any activity your application is running. 如果您不要求服务同时处理多个请求,则这是最佳选择。 This is a subclass of Service that uses a worker thread to handle all start requests, one at a time.