1

I have a room db where i saved my data , i want to delete that data after 5 days , starting from the date it was saved , is there anyway to do that guys , thank you

this is my room db deletion query

 @Query("DELETE FROM sporttable ")
    void deletedata(LiveModel list);

to be more clear : if data has been in 2019-10-24 , by 2019-10-29 i want it to be deleted , thank you guys

Taki
  • 3,290
  • 1
  • 16
  • 41
  • use workmanager and keep log of the date when the data is saved and check logs everyday via workmanager by defining work and if it's 10 then delete the data. – Jay Dangar Oct 24 '19 at 16:56
  • thank you for the answer , i have little enquiry , i can use workmanager but i read that in some chinese roms , that the workmanager would be killed and thus the operation will fail , is that true – Taki Oct 24 '19 at 16:58
  • https://stackoverflow.com/questions/50682061/android-is-workmanager-running-when-app-is-closed have a look the situations when it stops working – Jay Dangar Oct 25 '19 at 05:42
  • Thank you much for the answer – Taki Oct 25 '19 at 16:31
  • is it possible also using a query in the room db ! – Taki Oct 27 '19 at 13:21
  • Yes it is. write down query to fetch data and if you want to use variables, use it with :variablename and pass it as a parameter in a function. – Jay Dangar Oct 27 '19 at 13:43
  • i tried this query but still not giving me anything , can you please tell me your opinion , here is my query @Query("DELETE FROM livetable WHERE saved_match <= date('now','-1 day')") void deleteddata(); – Taki Oct 27 '19 at 13:45
  • The return type of a function is void, change it to appropriate datatype – Jay Dangar Oct 27 '19 at 13:46
  • deletion methods requires void or int as a return type , anf for me i want to delete the whole items in my room db , so should i pass the number of rows to delete though the rows number is not garanteed to be the same fix one each time – Taki Oct 27 '19 at 13:54
  • You can pass int as rowNumbers and instead of using Delete use query. – Jay Dangar Oct 27 '19 at 13:57
  • Passing both actually didnt work , i pass a method that returns void and another time one that returns the int and they both didnt work i dont know where could be the issue exactly – Taki Oct 27 '19 at 20:18

0 Answers0