Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement functionality like Facebook "New Story" feature?

I want to implement below functionality in my app.

enter image description here

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.

like image 969
Chirag Savsani Avatar asked Jan 05 '16 12:01

Chirag Savsani


1 Answers

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);
like image 187
Ravi Avatar answered Oct 17 '22 01:10

Ravi