skip to Main Content

I need to show feeds in my app and want to update UI real-time same like Twitter app?

As per my understandings, Below are the few ways,

  1. I can do this by continuous background call to API from service and update UI using handlers.
  2. I can register broadcast receiver and fire them once updated data is available and then update UI if the user is still on the same page.

However, I need to find the best way except this if possible because in future it can increase traffic of users/feeds.

2

Answers


  1. 1) I can do this by continuous background call to API from service and
    update UI using handlers.

    Don’t use this method, continuous background call of an API will reduce the performance.

    2) I can register broadcast receiver and fire them once updated data is available and then update UI if the user is still on the same page.

    When to send the broadcast?
    For this, you can get push notification from backend which tells your app that updated data is available and you can continue with your BroadcastReceiver

    Overall 2nd will be the option instead of 1st.

    Login or Signup to reply.
  2. You can use Firebase Cloud Messaging api to get the notification that your database has changed. In this case, the notification will be of type ‘data’. Once you get the notification from FCM, you need to handle your logic in onMessageReceived() method. From there you can use EventBus or BroadcastReceiver whichever suits your requirements.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search