How to delete database in Android app

前端 未结 4 1267
北海茫月
北海茫月 2021-01-05 15:58

How can I delete the database from the application?

相关标签:
4条回答
  • 2021-01-05 16:29

    Do you need to delete the actual db file or is it enough to just DROP the tables? I'd imagine the end result is the same and dropping the tables could be easier.

    0 讨论(0)
  • 2021-01-05 16:34
    File dbFile = getDatabasePath("your_db_file_name");
    boolean deleted = dbFile.delete();
    
    0 讨论(0)
  • 2021-01-05 16:42

    Old post, but I think its worth adding this in case this feature wasn't available back then. I use Context. For example, when your in MainActivity

    this.deleteDatabase("mydata.db");
    

    or when you have a context handle elsewhere

    context.deleteDatabase("mydata.db");
    
    0 讨论(0)
  • 2021-01-05 16:47

    Did you check deleteDatabase() method available in Android?

    0 讨论(0)
提交回复
热议问题