美文网首页
Running in a Background Service

Running in a Background Service

作者: Archo | 来源:发表于2016-09-20 14:01 被阅读0次

    使用IntentService

    create an IntentService

    RSSPullService extends IntentService
    override onHandleIntent()

    Define the IntentService in the Manifest

    android:exported is set to "false", the service is only available to this app.

    Create and Send a Work Request to an IntentService

    • Create a new Intent --- mServiceIntent
    • Call startService()
      Once you call startService(), the IntentService does the work defined in its onHandleIntent() method.

    Report Status From an IntentService

    • Create an Intent --- localIntent
    • Send the Intent
      LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent)

    Recieve Status Broadcasts from an IntentService

    • ResponseReceiver extends BroadcastReceiver
      Prevents instantiation --- DownloadStateReceiver()
      onReceive()
    • Create an IntentFilter
    • Register the BroadcastReceiver and its IntentFilter

    相关文章

      网友评论

          本文标题:Running in a Background Service

          本文链接:https://www.haomeiwen.com/subject/fcfoettx.html