In my app, onDataChange()
is not called when the device screen is locked.
code
mTicketCountReference = FirebaseDatabase.getInstance().getReference("private/" + EmployeeApp.getApp().getCurrentEmployee().getFirebaseUuid()+"/");
mTicketCountListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mAcceptCount = dataSnapshot.child("ticket_counts/accept").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/accept").getValue().toString()) : 0;
mAcceptEscalatedCount = dataSnapshot.child("ticket_counts/accept_escalated").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/accept_escalated").getValue().toString()) : 0;
mAcceptUnreadCount = dataSnapshot.child("ticket_counts/accept_unread").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/accept_unread").getValue().toString()) : 0;
mEscalateCount = dataSnapshot.child("ticket_counts/escalate").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/escalate").getValue().toString()) : 0;
mEscalateUnreadCount = dataSnapshot.child("ticket_counts/escalate_unread").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/escalate_unread").getValue().toString()) : 0;
mEscalateEscalatedCount = dataSnapshot.child("ticket_counts/esclate_escalated").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/esclate_escalated").getValue().toString()) : 0;
mMyTeamCount = dataSnapshot.child("ticket_counts/my_team").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/my_team").getValue().toString()) : 0;
mMyTeamEscalatedCount = dataSnapshot.child("ticket_counts/my_team_escalated").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/my_team_escalated").getValue().toString()) : 0;
mMyTeamUnreadCount = dataSnapshot.child("ticket_counts/my_team_unread").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/my_team_unread").getValue().toString()) : 0;
mMyTicketCount = dataSnapshot.child("ticket_counts/my_ticket").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/my_ticket").getValue().toString()) : 0;
mNewCount = dataSnapshot.child("ticket_counts/new").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/new").getValue().toString()) : 0;
mNewUnreadCount = dataSnapshot.child("ticket_counts/new_unread").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/new_unread").getValue().toString()) : 0;
mPreOrderCount = dataSnapshot.child("ticket_counts/pre_order").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/pre_order").getValue().toString()) : 0;
mRejectCount = dataSnapshot.child("ticket_counts/reject").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/reject").getValue().toString()) : 0;
mRejectedEscalatedCount = dataSnapshot.child("ticket_counts/rejected_escalated").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/rejected_escalated").getValue().toString()) : 0;
mRejectedUnreadCount = dataSnapshot.child("ticket_counts/rejected_unread").getValue() != null ? Integer.valueOf(dataSnapshot.child("ticket_counts/rejected_unread").getValue().toString()) : 0;
mAlertTimeStamp = Objects.requireNonNull(dataSnapshot.child("User_F_TS").getValue()).toString();
mAlertId = Integer.parseInt(Objects.requireNonNull(dataSnapshot.child("alert_id").getValue()).toString());
Log.d(TAG, "onMessageReceived: new Time Stamp: " + mAlertTimeStamp);
Log.d(TAG, "onMessageReceived: old Time Stamp: " + mSharedPreferences.getString(EmployeeApp.USER_TIME_STAMP, ""));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
mTicketCountReference.addValueEventListener(mTicketCountListener);
I need to display these items in a pop-up window. But it's working perfectly when the device is in foreground or background. Is there any workaround for this issue?