Android的独立服务 [英] Android stand alone service

查看:165
本文介绍了Android的独立服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始工作的针对Android的应用程序,是具体的 - 服务

我想创建一个服务(后台服务,迫使它本身来运行,隐藏的,所以它不能被关闭)。我没有关于如何构建它的想法。它是如何随后推出,以及如何使它适合这些要求。它需要开始从Android开始运行,所以我想这将是同样创建系统服务(或作为系统服务)。

您可能会问,为什么我需要的 - 我想这一些数据,定期发送给MySQL数据库无需任何用户交互 - 因此它需要连续运行

这将是非常有益的,如果你可以给我一个很好的开始,一个教程也许还是有些结构关键信息绘制。

一件事 - 我打靶的Andr​​oid 2.3,但如果这是不可能的,我想它是最低的Andr​​oid版

在此先感谢你们!


解决方案

  

我想创建一个服务(后台服务,迫使它本身来运行,隐藏的,所以它不能被关闭)。


幸好,这是不可能的。用户可以控制他们的设备,而不是你的,他们可以关闭任何他们想要的。


  

它需要开始从Android开始运行,所以我想这将是同样创建系统服务(或作为系统服务)。


系统服务是操作系统的一部分并且不能经由Android SDK中被创建。


  

您可能会问,为什么我需要的 - 我想这一些数据,定期发送给MySQL数据库无需任何用户交互 - 因此它需要连续运行


它做的不可以需要连续运行。这将是一个奇差的实现。

如果您想定期做一些事情,用 AlarmManager 的调度。这项工作应该由 IntentService ,因此该服务的可以走当工作完成的完成,这样你就不会占用内存中的所有的时间并使它的更多的可能用户会关闭你。如果你打算唤醒设备从睡眠模式恢复到做的工作,你应该看看 WakefulBroadcastReceiver ,或可能<一个href=\"https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CC0QFjAA&url=https://github.com/commonsguy/cwac-wakeful&ei=V0c8Usz_M5TI4AOjj4GYDg&usg=AFQjCNG72hXtdajjsqnYixgBdYDNmOxhlw&sig2=_s0lWPvOOpADXTnd-W1MhQ&bvm=bv.52434380,d.dmg\"相对=nofollow>我的 WakefulIntentService

I just started working on an application for Android, to be specific - a service.

I would like to create a service (background service, forcing itself to run, hidden, so it can't be shut down). and I don't have idea on how to construct it. How it is then launched and how to make it fit to those requirements. It needs to start running from the Android start, so I guess it would be created similarly to system services (or as a system service).

You may ask why I need that - I would like it to periodically send some data to MySQL DB without any user interaction - therefore it needs to run continuously.

It would be really helpful if You could give me a great start, a tutorial maybe or some structure drawing with crucial information.

One more thing - I am targetting Android 2.3, but if it's impossible, I'd like it to be the lowest possible Android version.

Thanks in advance guys!

解决方案

I would like to create a service (background service, forcing itself to run, hidden, so it can't be shut down).

Fortunately, this is not possible. Users have control over their device, not you, and they can shut down whatever they want.

It needs to start running from the Android start, so I guess it would be created similarly to system services (or as a system service).

System services are part of the operating system and cannot be created via the Android SDK.

You may ask why I need that - I would like it to periodically send some data to MySQL DB without any user interaction - therefore it needs to run continuously.

It does not need "to run continuously". That would be a singularly poor implementation.

If you want to do something periodically, use AlarmManager for the scheduling. The work should be done by an IntentService, so the service can go away when the work is done, so you are not tying up memory all of the time and making it more likely that the user will shut you down. If you plan on waking up the device out of sleep mode to do the work, you should look into WakefulBroadcastReceiver, or possibly my WakefulIntentService.

这篇关于Android的独立服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆