-2

I am currently developing a a project with multiple number of tables. So I created separate classes for storage and retrieval of data of each table.

Is there any better way so that I can reduce the number of classes? I am a beginner, so I am really uncertain about this.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sagar Acharya
  • 1,763
  • 2
  • 19
  • 38

3 Answers3

0

Here is description of all basic storage techniques:

Which Android Data Storage Technique to use?

But as @345 mentioned, you should try Realm Db. Its way easier to store and manage your data with it, in comparison to some SQLight wrappers.

Jarik Eng
  • 310
  • 2
  • 10
0

You can achieve this by making your code dynamic. Like you create some generalized methods and send the keys (table name, column name, row name) and values on real time when you are accessing those tables. But you have to do a-lot of work to do this, because all your tables will be different in structure. So you have to create methods for each table in that class or you can handle all possible scenarios through conditions (if/else or switch case).

Check this example, I hope it will help you.

http://www.androidhive.info/2013/09/android-sqlite-database-with-multiple-tables/

Zohaib Hassan
  • 984
  • 2
  • 7
  • 11
0

You must look around Room Persistence Library is an ORM between Java classes and SQLite:

Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. Documentation

Casablancais
  • 243
  • 1
  • 3
  • 9