Refreshing an Activity from service when Active

后端 未结 2 714
有刺的猬
有刺的猬 2020-12-14 22:50

I\'ve an app where I wish to update the Activity (List activity to be precise) only when the activity from Service is in foreground (Active)

I can use ListActivity I

相关标签:
2条回答
  • 2020-12-14 23:26

    The best solution is to have a centralized place. I consider this to be the best solution. Check this out:

    click here

    0 讨论(0)
  • 2020-12-14 23:33

    Do we have a generic solution to this ?

    Probably a dozen of them. Here are a few:

    • Have the activity register a listener object with the service in onResume() and remove it in onPause()
    • Send a private broadcast, picked up by the activity via registerReceiver() when it is in the foreground
    • Have the activity supply a "pending result"-style PendingIntent to the service
    • Use a ResultReceiver
    • Use a ContentProvider, with the activity holding onto a Cursor from the provider, and the service updating the provider

    This set of projects demonstrates the first three, in the context of remote services.

    0 讨论(0)
提交回复
热议问题