您的位置:首页 > 移动开发 > Android开发

Android 开发文档 程序基础 ——Services组件

2010-06-19 10:44 387 查看
service没有可视化用户界面,运行在后台,在不确定的时间。service都是extends于Service基类。

也可以链接或者绑定到一个运行中的service。连接时可以通过一个可视化界面来交互。

像其他组件一样,service是运行程序进程的主线程中。所以service不会block其他组件或者用户界面,而是为time-
consuming tasks?耗时的任务产生另一个线程。

转自我的android博客

原文

Services
A
service
doesn’t have a visua
l user
interface, but rather runs in the background for an indefinite period
of time.Each service extends the Service
base class.

A prime example is a media player playing songs from a play
list. The player application would probably have one or more activities
that allow the user to choose songs and start playing them. However,
the music playback itself would not be handled by an activity because
users will expect the music to keep playing even after they leave the
player and begin something different. To keep the music going, the
media player activity could start a service to run in the background.
The system would then keep the music playback service running even
after the activity that started it leaves the screen.

It’s possible to connect to (bind to) an ongoing service (and
start the service if it’s not already running). While connected, you
can communicate with the service through an interface that the service
exposes. For the music service, this interface might allow users to
pause, rewind, stop, and restart the playback.

Like activities and the other components, services run in the
main thread of the application process. So that they won’t block other
components or the user interface, they often spawn another thread for
time-consuming tasks (like music playback). See Processes and Threads,
later.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: