I've been trying to make this work from
How to delete firebase data after "n" days
but it's not working for me.
Here's what I'm doing,
In my "A" activity, I have a button that will save this chunk of data, with a 'timeStamp' child which holds the timestamp value. (.setValue(ServerValue.TIMESTAMP);)
After pressing the button, it saves the data successfully. Then, it starts the next activity, where we wait.
But instead of deleting after '30' days, it deletes it straight away.
I have a method that works exactly like the answer by Frank
long cutoff = new Date().getTime() - TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS);
Query oldBug = mDatabase.orderByChild("timeStamp").endAt(cutoff);
oldBug.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot itemSnapshot: snapshot.getChildren()) {
itemSnapshot.getRef().removeValue();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
But it's not deleting it after some time, as soon as it is posted.
Thank you.
EDIT: