Okay so i am making a very basic app. (Its not a chat app) But i want to do something that chat apps do. Plus i will be the only user for this app.
So what i want is, I am using firebase, so i want to create a listener that never expires, it reads for new data (or changes) even when app is closed and removed from memory, so even if i close it from recents, it should keep listening and whenever some changes occur, a function should run.
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post object and use the values to update the UI
Post post = dataSnapshot.getValue(Post.class);
// ...
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
mPostReference.addValueEventListener(postListener);