[英]how to exec long time task only use BroadcastReceiver in android?
I 'm writing a backgroud app only can use service. 我正在写一个只能使用服务的backgroud应用程序。 I'use BroadcastReceiver start service.
我正在使用BroadcastReceiver启动服务。 Sometimes it works well, but some sometimes it doesn't work.
有时它运作良好,但有时却无法运作。
I know the reason is BroadcastReceiver exec liftcycle is 10 seconds, so use it start a long time task will not be end. 我知道原因是BroadcastReceiver exec提升周期是10秒,所以使用它启动很长时间任务不会结束。
Intent i = new Intent();
i.setClass(context, RegisterService.class);
context.startService(i);
What should I do if I want to execute a long time task only use BroadcastReceiver and service? 如果我只想使用BroadcastReceiver和服务执行长时间任务,该怎么办?
Make sure your service is not executing on the main thread. 确保您的服务不在主线程上执行。 Consider using an IntentService , it does the right thing out of the box.
考虑使用IntentService ,它提供了开箱即用的正确方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.