Advertisement
Guest User

Clear database for android app

a guest
Jun 19th, 2024
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | Source Code | 0 0
  1. public class Repository {
  2.     public void deleteAllExcursions() {
  3.         databaseExecutor.execute(() -> {
  4.             mexcursionDAO.deleteAllExcursions();
  5.         });
  6.     }
  7.  
  8.     public void deleteAllVacations() {
  9.         databaseExecutor.execute(() -> {
  10.             mvacationDAO.deleteAllVacations();
  11.         });
  12.     }  
  13. }
  14.  
  15. public interface ExcursionDAO {
  16.     @Query("DELETE FROM excursion")
  17.     void deleteAllExcursions();
  18. }
  19.  
  20. public interface VacationDAO {
  21.     @Query("DELETE FROM vacations")
  22.     void deleteAllVacations();
  23. }
  24.  
  25. public class VacationActivity extends AppCompatActivity {
  26.  
  27.    @Override
  28.     protected void onCreate(Bundle savedInstanceState) {
  29.         clearAllExcursions();
  30.         clearAllVacations();
  31.     }  
  32.    
  33.    
  34.  private void clearAllExcursions() {
  35.         repository = new Repository(getApplication());
  36.         repository.deleteAllExcursions();
  37.         Log.d("VacationActivity", "All excursions cleared.");
  38.     }
  39.  
  40.     private void clearAllVacations() {
  41.         repository = new Repository(getApplication());
  42.         repository.deleteAllVacations();
  43.  
  44.     }
  45. }
Tags: Java Android
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement