简体   繁体   中英

How to implement functionality like Facebook “New Story” feature?

I want to implement below functionality in my app.

在此处输入图片说明

How can i do this?

I have 2 ways in my mind :

  1. Get total post count from webservice after every 1 minute or some time. But for that I need to run one Thread continuously in background so may be performance issue will arise.(Battery performance)

  2. Can I do this functionality with Notification service?

or If any one have another Idea please suggest me.

It would be good idea to do it with push notification . You can set flag in push notification and filter it according to your need.

create Broadcast which will be called when you receive notification of perticular flag.

Intent intent = new Intent("newStory");
sendBroadcast(intent);

on that broadcast receive method show that Image or Layout .

private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("receiver", "Got message: ");
        //show new story image
    }
};

In onResume() register your Broadcast .

registerReceiver(mMessageReceiver, new IntentFilter("newStory"));

In onPause() unregister it.

unregisterReceiver(mMessageReceiver);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM