[英]Which service should I use?
I got 2 classes: A(Activity subclass) which generates the phone location infinitely and class B (thread subclass) which takes the location from A and send it to the db. 我有2个类:A(活动子类),它无限生成电话位置;类B(线程子类),它从A获取位置并将其发送到数据库。 Since it's an activity it's stop generating the locations once I close my application so I guess service would make the job.
因为这是一项活动,所以一旦我关闭我的应用程序,它就会停止生成位置,因此我猜服务将完成这项工作。
I read about services in here(http://developer.android.com) 我在这里(http://developer.android.com)了解有关服务的信息
but I couldn't understand which service should I use and how? 但我不知道应该使用哪种服务以及如何使用? The change that I'm planning to do is to turn A into a service and create class C(activity) which start & stop A.
我打算做的更改是将A变成服务,并创建启动和停止A的类C(活动)。
Thanks. 谢谢。
You can use Timer for this.. 您可以为此使用计时器。
private void startservice() {
timer.scheduleAtFixedRate( new TimerTask() {
public void run() {
//Do whatever you want to do every “INTERVAL”
}
}, 0, INTERVAL);
; }
Execute or call a method at a certain time. 在特定时间执行或调用方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.