Android 开发之Services组件
2010-06-12 19:46:00 来源:WEB开发网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.
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接