I study how to work with SQLite when creating android applications, doing a small task on test development (quiz). This test stores questions and answers in a database, I make it based on a video of one German - if necessary, I will give a link to the channel / code.

So, in the code of the method that fills the database with questions, I made a mistake - when copying the first line I did not change it inadvertently, and instead

private void fillQuestionsTable() { Question q1 = new Question("A is correct", "A", "B", "C", 1); addQuestion(q1); Question q2 = new Question("B is correct", "A", "B", "C", 2); addQuestion(q2); Question q3 = new Question("C is correct", "A", "B", "C", 3); addQuestion(q3); Question q4 = new Question("A is correct again", "A", "B", "C", 1); addQuestion(q4); Question q5 = new Question("B is correct again", "A", "B", "C", 2); addQuestion(q5); } 

I have had

  private void fillQuestionsTable() { Question q1 = new Question("A is correct", "A", "B", "C", 1); addQuestion(q1); Question q1 = new Question("A is correct", "A", "B", "C", 1); addQuestion(q1); Question q1 = new Question("A is correct", "A", "B", "C", 1); addQuestion(q1); Question q1 = new Question("A is correct", "A", "B", "C", 1); addQuestion(q1); Question q1 = new Question("A is correct", "A", "B", "C", 1); addQuestion(q1); } 

Accordingly, everything is recorded in the database.

I immediately corrected this error after I found it, but when I started the emulator (I usually work with the Nexus 5X API 26 x86 device), nothing changed - every time the same first question was displayed.

I checked that already different questions are entered into the database using the DB browser for SQLite - indeed, there were already different questions in the database table, and not the first one, repeated five times, as at the very beginning.

As a result, I thought of launching another device on the emulator (Nexus 5 API 26) - and it all worked. It turns out that for the first device, the data transmitted for the first time to the database has been cached.

Somehow you can delete the cache only for this device in the emulator or will it be easier to delete the Nexus 5X API 26 x86 and then reinstall it?

  • one
    The problem is not related to the emulator, on the real device will be the same. You can simply delete the application under test from the device, and the created database will be deleted with it. In general, the problem is strange (if the records have changed in the database, then they should also change in the application) and to answer why this is not enough information. On the development of the quiz, I can recommend reading P.Datel's books "Android for developers" and B. Phillips "Android. Programming for professionals", these games are described in detail and in Russian - pavlofff
  • I installed a copy of the Nexus 5X API 26 x86 in the emulator - everything is fine now it runs and works ... So I think that after all something is cached in a specific device in the emulator. - Vitaliy Tretyakov
  • It’s much more likely that there was something wrong with your code than inexplicable caching on only some emulators. The emulator is not a copy of any device at all and the names in them only serve to distinguish one from the other. The difference in emulators lies only in the emulated characteristics, such as memory size, screen size, API version, and so on. - their separate instances do not possess any unique properties of real devices, besides the emulation parameters specified in the settings. You can edit the existing Wirth. device and you will have a Nexus 5 with 128MB of RAM - pavlofff

0