- I have implemented a
Service
that receives notifications sent from the server. - I'm currently using a broadcast receiver to send data. The Broadcast Listener is updating the
Activity
just fine. However, when data is sent when the Activity is not on "onResume" state, the data is not received. - I got interested in using RXjava because I believe it could resolve the issue but don't know where to start.
The problem: When the activity is not on the foreground, the Activity is not updating.
Not in the foreground: Meaning that I have called unregisterReceiver
to unregister in my onPause
method.
My current user case: I'm using a Service
to intercept notification sent from server using FCM
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "[" + MyFirebaseMessagingService.class.getName() + "]=";
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onNewToken(String token) {
Log.d(TAG, "Refreshed token: " + token);
}
/**
* Handle time allotted to BroadcastReceivers.
*/
private void handleNow() {
Log.d(TAG, "Short lived task is done.");
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
// Handle message within 10 seconds
handleNow();
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
// <-----------RX JAVA Observable Implementation----------->
// I would like to use Rx java to send data to my activity ONLY if the activity is in the foreground
// because data will be used to update the UI
}
@Override
public void onDeletedMessages() {
super.onDeletedMessages();
}
}
I looked into RXjava
and I find out that the library takes care of asynchronous operations, but what I'm curious about is:
if there is any functions within RXjava
that will automatically update that data once the Activity is back on the foreground?
If not, what are the other alternatives?
Maybe this question has already been answered but I could not find a precise user case to what I'm trying to achieve in here. Also, I might be asking the question wrongly, but that just explains my confusion here