Refreshing activity on receiving gcm push notification

后端 未结 7 1316
自闭症患者
自闭症患者 2020-11-29 16:45

Update: GCM is deprecated, use FCM

How to refresh activity on receiving gcm push notification<

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 17:25

    The accept answer is indeed correct for the "Refreshing activity on receiving gcm push notification" (I've upvoted it too). But if you only want to update a ListView that's being displayed you don't need a broadcast receiver.

    Your GCM listener service can update the database using a ContentProvider rather than inserting a direct sql query.

    Then you can rely on the notifyChange method on the ContentResolver to do the trick.

    Notify registered observers that a row was updated. To register, call registerContentObserver(). By default, CursorAdapter objects will get this notification. If syncToNetwork is true, this will attempt to schedule a local sync using the sync adapter that's registered for the authority of the provided uri. No account will be passed to the sync adapter, so all matching accounts will be synchronized.

提交回复
热议问题