WEB开发网
开发学院手机开发Android 开发 Android 开发之Services组件 阅读

Android 开发之Services组件

 2010-06-12 19:46:00 来源:WEB开发网   
核心提示:service没有可视化用户界面,运行在后台,Android 开发之Services组件,在不确定的时间,service都是extends于Service基类,service是运行程序进程的主线程中,所以service不会block其他组件或者用户界面,也可以链接或者绑定到一个运行中的service,连接时可以通过一个

service没有可视化用户界面,运行在后台,在不确定的时间。service都是extends于Service基类。

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

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

原文

Services A service doesn’t have a visual 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.

Tags:Android 开发 Services

编辑录入:coldstar [复制链接] [打 印]
赞助商链接