Best way to store dynamic data?

Multi tool use
Multi tool use


Best way to store dynamic data?



I am developing a launcher for Android and need some advice on designing my persistent storage system.



I wish for people to be able to create different categories for their apps (e.g Media, Utilities, Social). Users must be able to choose the order of their apps and apps can appear in more than one category. Users can update the order of the apps and order should persist on restart. I would also like to keep track of how often apps are launched so that I can have an automatic 'most used' category.



I have had 2 approaches but neither seem ideal:



Save the list of apps to a file (JSON or other), taking note of the package name and position in the list. When required bring this file in and sort by order



Save the list in an SQLlite database, either:



Option 1 I feel would be tricky to keep dynamic and unsure of efficiency, so I prefer option 2 because its's simple to update and automatically Order By, however it may be overkill to use a DB for this.



Any advice or other possible solutions would be great! Thanks




2 Answers
2



I'd go for a database approach. I think storing data in a file is perhaps a good choice for small applications where the data don't grow and you flush changes max once before the application is destroyed.



If you want to avoid the boilerplate code of SQLite, then consider Room. Alternatively, you may want to have a look at Realm which is an alternative to SQLite.





Thanks George, given that Room (which I would like to utilise) doesn't support adding columns to existing databases, do you think I am stuck with using a table for each category?
– FrazorLazer
Jul 3 at 15:08





I'm not sure I fully understand why you need to have one table for each category. Wouldn't it be sufficient if you had one table with columns "package_name" and "list_position" where the first one would also be the primary key?
– George
Jul 3 at 15:26





I'd like to allow the user to create their own categories, so columns could be "package_name", "listposition_media", listposition_social" for example. Then if the user wishes to create a new category utilities they would need add a column listposition_utilities dynamically.
– FrazorLazer
Jul 3 at 19:37





Could you share how would your Java/Kotlin models look? For example, will you have a Category class or would a HashMap represent your data better?
– George
Jul 4 at 12:08





I haven't yet defined what my models will be for sure as I think they would be affected by which method I use here. A closer look at Realm, as you suggested, and I feel it may be the best way forward. For example Category extends RealmObject { categoryName: String, position: Int } and AppListItem extends RealmObject() { appTitle : String, package: String, categories : RealmList<Category> }
– FrazorLazer
Jul 5 at 20:49



If your function is limited then a file based approach works, your approach depends on basis of features you want to have like



-->add i.e (append) specific index or you resorting or shuffling of data is needed.



-->consuming the data i.e If accessing the data in ordered fashion or filtering on multiple features.



Storing data in a file is generally preferred for a small collection of key-values like android Sharedpref itself.
Depending on the functionalities your launcher has the file system gets complex and slower accessing and modification in which case it(file) won't be the best way to store the list of apps (& other info if needed) in a file.



Building a database would help overcome all the complex for future functions like different sorting and other features.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

0hV8vGt6Fu,uwN1aiV0Ru4Wox,CfFdZstj0,2pv6w3DJLJ ofqNC7Tef UHdHv
M tGM rwV1Nyoe

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications