Creating a custom News Feed
Learn how to create a custom News Feed for the Braze Android SDK.
News Feed is being deprecated. We recommend migrating to our Content Cards messaging channel instead—it’s more flexible, customizable, and reliable. To get started, check out Migrating from News Feed.
Creating a custom feed
You can create and display a custom feed by populating your own views with data from Braze’s News Feed models.
Step 1: Subscribe to feed updates
Declare a private variable in your custom feed class to hold your subscriber.
1
2
// subscriber variable
private IEventSubscriber<FeedUpdatedEvent> mFeedUpdatedSubscriber;
In your custom feed activity’s Activity.onCreate()
, add the following code so you can subscribe to feed updates from Braze.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Remove the old subscription first
Braze.getInstance(context).removeSingleSubscription(mFeedUpdatedSubscriber, FeedUpdatedEvent.class);
mFeedUpdatedSubscriber = new IEventSubscriber<FeedUpdatedEvent>() {
@Override
public void trigger(final FeedUpdatedEvent event) {
// This list of Card objects included in the FeedUpdatedEvent should be used to populate your News Feed views.
List<Card> cards = event.getFeedCards();
// your logic here
}
};
Braze.getInstance(context).subscribeToFeedUpdates(mFeedUpdatedSubscriber);
// Request a refresh of feed data
Braze.getInstance(context).requestFeedRefresh();
We recommend that you unsubscribe when your custom feed activity moves out of view, by adding the following code to your activity’s onDestroy()
lifecycle method.
1
Braze.getInstance(context).removeSingleSubscription(mFeedUpdatedSubscriber, FeedUpdatedEvent.class);
Step 2: Log analytics
When you use a custom view, you’ll need to log analytics manually since automatic handling is only available through a Braze view.
Action | Method |
---|---|
Log a display of the feed | Braze.logFeedDisplayed() |
Log an impression | Card.logImpression() |
Log a click on a Card | Card.logClick() |