I am not familiar with Room Database. I want to clear the data from some tables when I click on button. I have the similar code in IOS but I am not sure where I have to write this method and call this delete function and how to access the tables. Can anyone help me on this in android.
IOS code:
class ApplicationResetManager: NSObject {
static let shared: ApplicationResetManager = ApplicationResetManager()
var cloSuccess:((_ isSuccessfull: Bool)->Void)?
func clearAllData(completion: (Bool) -> Void) {
let isSyncGoingOn = ApplicationManager.shared.isSyncGoingOn
if let currentUser = ApplicationManager.shared.currentUser, currentUser.id! > 0, isSyncGoingOn == false {
let dbQueue = DatabaseManager.shared.dbQueue!
do {
// 4. Access the database
try dbQueue.inTransaction { db in
do {
try UserLocations.deleteAll(db)
try LineLayoutEquipment.deleteAll(db)
try LineLayout.deleteAll(db)
try Survey.deleteAll(db)
try HealthCheck.deleteAll(db)
try HealthCheckData.deleteAll(db)
try ActionItem.deleteAll(db)
try Equipments.deleteAll(db)
try EquipmentIndustry.deleteAll(db)
try Comments.deleteAll(db)
try PlantAreas.deleteAll(db)
try PlantAreasIndustrys.deleteAll(db)
try Applications.deleteAll(db)
try ApplicationsIndustrys.deleteAll(db)
try SurveyLineLevel.deleteAll(db)
try HealthCheckLineLevel.deleteAll(db)
try ActionItemLineLevel.deleteAll(db)
try ActionItemLineLvlComments.deleteAll(db)
UserDefaults.standard.set([], forKey: arr_selected_company)
ApplicationManager.shared.currentUser.defaultCompanyId = nil
completion(true)
return .commit
} catch {
completion(false)
return .rollback
}
}
} catch {
completion(false)
}
} else {
print("Sync is already in progress")
}
}
}