0

我正在写一个只能使用服务的背景应用程序。我使用 BroadcastReceiver 启动服务。有时它工作得很好,但有时它不起作用。

我知道原因是 BroadcastReceiver exec liftcycle 是 10 秒,所以使用它启动很长时间的任务不会结束。

Intent i = new Intent();
i.setClass(context, RegisterService.class);
context.startService(i);

如果我只想使用 BroadcastReceiver 和服务来执行长时间的任务,我该怎么办?

4

1 回答 1

1

确保您的服务不在主线程上执行。考虑使用IntentService,它开箱即用。

于 2012-06-14T07:45:52.367 回答