安卓和闹钟管理器
我编写将使用警报管理器的应用程序。首先,我设置警报管理器每 20 秒运行一些服务。然后服务启动一些线程。这是我的服务代码:
public int onStartCommand(Intent intent, int flags, int startId) {
ExtendedLog.i(TAG, "On start command");
Thread t = new Thread(wat);
t.start;
this.stopSelf();
return START_STICKY;
}
我的问题是它只能正常运行几分钟。之后警报管理器启动服务但线程未启动。我实在不知道问题出在哪里。你们中有人知道它可能出了什么问题吗?感谢您的任何帮助。
I write application which will use alarm manager. First I set up alarm manager to run some service every 20sec. Then service start some Thread. Here code of my service:
public int onStartCommand(Intent intent, int flags, int startId) {
ExtendedLog.i(TAG, "On start command");
Thread t = new Thread(wat);
t.start;
this.stopSelf();
return START_STICKY;
}
My problme is that this running properly only for few minutes. After that alarm manager starts service but thread does not start. I really dont know where is problem. Do anyone of you know what may be wrong with it? Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望线程继续运行,为什么要停止服务?
查看 Service 文档:
因此,由于您没有按照请求在
onDestroy
中停止线程,系统可能会自行中断并停止它们。你想在这里做什么?开始一个新线程&每 20 秒新服务可能(我什至可能会说显然)不是实现您需要执行的任何操作的最佳方式...可运行
wat
运行的代码是什么?Why are you stopping the service if you want the thread to keep running?
Looking in the Service documentation:
So since you did not stop your threads in
onDestroy
as requested , the system probably interrupts and stops them on its own.What are you trying to do here? Starting a new thread & new service each 20 seconds is probably (I might even say obviously) not the best way to implement whatever you need to do... What is the code the runnable
wat
runs?