Service

A Service is code that is long-lived and runs without a UI. A good example of this is a media player playing songs from a play list. In a media player application, there would probably be one or more activities that allow the user to choose songs and start playing them. However, the music playback itself should not be handled by an activity because the user will expect the music to keep playing even after navigating to a new screen. In this case, the media player activity could start a service using Context.startService() to run in the background to keep the music going. The system will then keep the music playback service running until it has finished. Note that you can connect to a service (and start it if it's not already running) with the Context.bindService() method. When connected to a service, you can communicate with it through an interface exposed by the service. For the music service, this might allow you to pause, rewind, etc.

Content Provider

Applications can store their data in files, a SQLite database, preferences or any other mechanism that makes sense. A content provider, however, is useful if you want your application's data to be shared with other applications. A content provider is a class that implements a standard set of methods to let other applications store and retrieve the type of data that is handled by that content provider.

服务

服务是没有界面的长生命周期的代码。一个很好的例子是媒体播放器从列表中播放歌曲。在一个媒体播放器程序中,大概要有一个或多个活动(activity)来供用户选择歌曲并播放它。然而,音乐的回放就不能使用活动(activity)了,因为用户希望他导航到其他界面时音乐继续播放。这种情况下,媒体播放器活动(activity)要用Context.startService()启动一个服务来在后台运行保持音乐的播放。系统将保持这个音乐回放服务的运行直到它结束。注意一下,你要用Context.bindService()方法连接服务(如果它没有运行,要先启动它)。当连接到服务后,你可以通过服务暴露的一个接口和它通信。对于音乐服务,它允许你暂停、倒带,等等。

内容提供者(或不做翻译)

应用程序可以存储它们的数据在文件中,SQLite数据库中,偏好设置(preference)或其他可以起作用的机制。一个内容提供者,如果你想要程序的数据贡献给其他程序,它将非常有用。内容提供者是一个实现了标准方法集的类,可以让其他程序存储和恢复被内容提供者使用的数据类型。

更多相关文章

  1. Android 扫描SDCard上的音乐文件以及监听扫描事件
  2. android 音乐播放器源码
  3. Android应用实例之----基于Service与ContentProvider的音乐播放
  4. Android控制后台音乐播放器暂停,播放
  5. Android:音乐特效控制
  6. Android音乐播放器开发小记——项目简介
  7. Android 6.0耳机hook按键接听和挂断电话;音乐中短按下一首,长按
  8. 基于Android的MediaPlayer的音乐播放器的封装

随机推荐

  1. TextView 文字加图片显示效果
  2. Android自定义radiobutton(文字靠左,选框
  3. Android中应用界面布局总结
  4. Android(安卓)Studio控件属性大全
  5. Android样式开发
  6. Android中TextView中加图片,超链接,部分字
  7. Android(安卓)单元测试之JUnit和Mockito
  8. Android(安卓)背景渐变 渐变背景 shape
  9. Android安全加密:Https编程
  10. 在Android(安卓)Studio中下载Android(安