is it possible to delete some data from firebase on specific time, when the app is already closed by user?
foreground service will consume too much battery and work manager is not used for accuracy
is it possible to do with cloud functions?
I'm new to android development so i have no clue how to handle such kind of problem.
Yes you can do it in cloud functions.
If you know exaclty when you want to trigger your action, you can add crontab with firebase functions https://firebase.google.com/docs/functions/schedule-functions
For example:
exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *')
.timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles
.onRun((context) => {
console.log('This will be run every day at 11:05 AM Eastern!');
return null;
});