android - onChildAdded is fired on every app start, but no new entries in the database -
on every start of app, receive same "onchildadded" actions. app thinks, these child added recently. in database beginning. when close app , start again, receive these actions again. everytime.
i call
firebasedatabase.getinstance().setpersistenceenabled(true);
in application class.
how can solve issue, listeners called, when new data added database?
the easiest way keep key of newest item user has seen in local storage (e.g. sharedpreferences
). when start activity again, start @ key:
string lastseenkey = sharedpreferences.getstring("lastseenkey", "-"); ref.orderbykey(). .startat(lastseenkey) .addchildeventlistener(...
and in onchildadded()
make sure store latest key in shared preferences.
Comments
Post a Comment