Class BatchInboxFetcher
Once you get your BatchInboxFetcher instance, you should call fetchNewNotifications(com.batch.android.BatchInboxFetcher.OnNewNotificationsFetchedListener)
to fetch the initial page of messages: nothing is done automatically.
This method is also useful to refresh the list.
In an effort to minimize network and memory usage, messages are fetched by page (batches of messages):
this allows you to easily create an infinite list, loading more messages on demand.
While you can configure the maximum number of messages you want in a page, the actual number of returned messages can differ, as the SDK may filter some of the messages returned by the server (such as duplicate notifications, etc...).
As BatchInboxFetcher caches answers from the server, instances of this class should be tied to the lifecycle of the UI consuming it (if applicable).
For example, you should keep a reference to this object during your Activity's entire life.
Another reason to keep the object around, is that you cannot mark a message as read with another BatchInbox instance that the one
that gave you the message in the first place.
A BatchInboxFetcher instance will hold to all fetched messages: be careful of how long you're keeping the instances around.
You can also set a upper messages limit, after which BatchInbox will stop fetching new messages, even if you call fetchNextPage.
Note: You will always be called back on the thread that you instantiated BatchInboxFetcher on. use setHandlerOverride(android.os.Handler)
if you want to change that behaviour.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Fetch new notifications.
WhilefetchNextPage(com.batch.android.BatchInboxFetcher.OnNextPageFetchedListener)
is used to fetch older notifications than the ones currently loaded, this method checks for new notifications.void
Fetch a page of notifications.
Calling this method when no messages have been loaded will be equivalent to callingfetchNewNotifications(com.batch.android.BatchInboxFetcher.OnNewNotificationsFetchedListener)
Warning: callbacks might not be called on the thread you're expecting.Returns a copy of all notifications that have been fetched until now, ordered by reverse chronological order (meaning that the first message is the newest one, and the last one the oldest).boolean
hasMore()
Returns whether all of the user or installation's notifications have been fetched.void
Marks all notifications as read.void
markAsDeleted
(BatchInboxNotificationContent notification) Mark a specific notification as deleted.void
markAsRead
(BatchInboxNotificationContent notification) Mark a specific notification as read.void
setFetchLimit
(int fetchLimit) Maximum number of notifications to fetch.void
setFilterSilentNotifications
(boolean filterSilentNotifications) Sets whether the SDK should filter silent notifications (pushes that don't result in a message being shown to the user).void
setHandlerOverride
(Handler handler) Specify a handler to post the callbacks on.void
setMaxPageSize
(int maxPageSize) Number of notifications to fetch on each call, up to 100 messages per page.
-
Method Details
-
setMaxPageSize
public void setMaxPageSize(int maxPageSize) Number of notifications to fetch on each call, up to 100 messages per page. Note that the actual count of fetched messages might differ from the value you've set here. -
setFetchLimit
public void setFetchLimit(int fetchLimit) Maximum number of notifications to fetch. This allows you to let Batch manage the upper limit itself, so you can be sure not to use a crazy amount of memory. If you want to fetch unlimited messages, set this property to 0.- Parameters:
fetchLimit
- Limit of notifications to fetch. Default: 200
-
setFilterSilentNotifications
public void setFilterSilentNotifications(boolean filterSilentNotifications) Sets whether the SDK should filter silent notifications (pushes that don't result in a message being shown to the user). Default: true -
hasMore
public boolean hasMore()Returns whether all of the user or installation's notifications have been fetched. If this method returns true, calling fetchNextPage will always return an error, as there is nothing left to fetch. Also artificially returns true if the maximum number of fetched messages has been reached. -
markAsRead
Mark a specific notification as read.- Parameters:
notification
- The notification to be marked as read.
-
markAllAsRead
public void markAllAsRead()Marks all notifications as read. -
markAsDeleted
Mark a specific notification as deleted.- Parameters:
notification
- The notification to be marked as deleted.
-
getFetchedNotifications
Returns a copy of all notifications that have been fetched until now, ordered by reverse chronological order (meaning that the first message is the newest one, and the last one the oldest). Note that this array will be empty until you callfetchNewNotifications(com.batch.android.BatchInboxFetcher.OnNewNotificationsFetchedListener)
, and will only grow on subsequent fetches. This operation is quite extensive: you should cache this result until you call fetch*. -
fetchNewNotifications
Fetch new notifications.
WhilefetchNextPage(com.batch.android.BatchInboxFetcher.OnNextPageFetchedListener)
is used to fetch older notifications than the ones currently loaded, this method checks for new notifications. For example, this is the method you would call on initial load, or on a "pull to refresh". If new notifications are found, the previously loaded ones will be kept if possible, but might be cleared to ensure consistency. For example, if a gap were to happen because of a refresh, old notifications would be removed from the cache.- Parameters:
listener
- An optional listener can be executed on success or failure with either the fetched notifications or the detailed error.
-
fetchNextPage
Fetch a page of notifications.
Calling this method when no messages have been loaded will be equivalent to callingfetchNewNotifications(com.batch.android.BatchInboxFetcher.OnNewNotificationsFetchedListener)
Warning: callbacks might not be called on the thread you're expecting. SeesetHandlerOverride(android.os.Handler)
- Parameters:
listener
- An optional listener can be executed on success or failure with either the fetched notifications or the detailed error.
-
setHandlerOverride
Specify a handler to post the callbacks on. By default, this is the thread that you've created the inbox fetcher on.- Parameters:
handler
- Handler to post the callbacks on
-