Android 处理程序与服务

标签 android android-service background-process android-handler

我有一个应用程序,即使应用程序也关闭,也必须每分钟检查一次网站。我不知道我应该用什么来做到这一点。处理程序还是服务? 谢谢!约翰

最佳答案

服务

A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background.

处理程序:

A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.

您需要的是服务

关于Android 处理程序与服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40326588/

相关文章:

android - 使用 zip 时保持一些文件未压缩

android - 选项卡的自定义 Holo 主题

android - 如何将 IBluetoothA2dp.aidl 接口(interface)添加到我的项目中?

java - 通过服务选择的插件架构

java - 让Chathead气泡在android中永远运行

ios - 核心数据 后台慢速和后台保存、sqlite后台和mergeChangesFromContextDidSaveNotification

php - 异步PHP

android - 在自定义 View 中使用进度条?

android - 无法使用 NotificationListenerService 取消通知

ios7 - 当应用程序在 iOS 7 后台运行时将数据发送到服务器