Android with Kotlin best ways to storage a custom class [closed] - android

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
this is the first time that I need to store some data permanently so I would like some suggestions before to proceed. I've read that there are different ways to store data on an Android device:
Internal storage
Shared Preference (but if I've understood is just for symple data like an option)
Shared storage (but I don't need to share data among other apps)
Database
I can't understand what is the best option for me between the first and the last.
My case
I have a list of book with title, subtitle, cover image and each book contains a list of cards with title, optional image, (audio if possible), other stuff.
So, I have to store an arraylist of a custom class that includes another arraylist of anothercustomclass and some text/image
Which approach should I take?
Thanks

Frankly, the case description is much too limited to give an informed advice (so the question should be closed).
But if you have doubts, then the safe / default choice is the database. It might come with big overhead for some cases (like when it's enough to serialize the whole arraylist to a blob and store as a single file), but you are less likely to paint yourself into a corner.
Addition (after a comment)
When using a database, you don't store objects directly (because what an sql database stores are "relations" which you can think of as "sets of rows", not objects). Instead you have some code (custom or from a library) that translates an object into a row (or multiple rows) for storage and some code that translates it the other way.
If you want to store the actual objects, then serialization to a file is pretty much the only way.

Related

Best practice: store image and text in Android [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am doing a simple app where I take a picture, fill some text from the UI and store the image + text together.
Eventually the user can select the picture from a recyclerview and edit the associated text (or delete the whole image + text group).
I have no hint on what kind of data structure should be used.
I heard that SQL lite should be used for such tasks - since the text data could change according to the user actions, but I think that using tables (one or more) for the purpose of storing images and text could be overkill - also because I don't expect to have a lot of images in my app.
I'm wondering if any other data structure is available for this purpose (similar to C strctures, or python dictionaries).
Also, any kind of hint about keyword to search for this topic or resource would be really appreciated.
Just for the sake of discussion, I am developing using kotlin.
For storing images, you should store them as files, and store file paths of those images in the database with text. Moreover, when you read it back you can use Picasso or Glide to load those image paths into ImageView.
Also, if you want to store images in external storage, make you request runtime-permission and add permission to the manifest file.
However, if you store files in internal storage, you don't need to request permission.
Learn more about Runtime-Permission and Storage in Android.
I would suggest use Room for working with SQLite in Android.

android - dictionary to translate strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a lot of String code values that come from server, and I want to translate this codes to strings.
I can get key and value (code : string) from server every week and store/update them.
What is the best way to store, update, and read/use this data, over whole activities of app?
Thanks.
You have the following alternatives:
Shared Preferences - a persistent key value store. You can write values, that are stored to files, that are accessible in the app context.
Database - use the built-in SQLite instance or a third party DB of your choice. The data is persisted and also accessible from within the app context. Extracting the values may be a bit over complex for your case.
Plain files in a custom format that fits your use case - you can create and store files that are private to your app and store and extract info from them. You will have to deal with the file format and operations in a custom way.
As a whole, fetching your string resources from the network is not a very good approach. In this way you have to deal with localisation and internationalisation in a custom way and can't use the built-in goodies provided by the Android OS.

(Android) better to store a single table of data in sqlite or as a text file? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I've a single data table, fully structured, that my app will require.
It consists of a few thousand rows, three columns separated by spaces (in the text file I load from), and I need these to have specific priority assigned to them.
That priority is stored as an int and will be modified.
I considered keeping the whole thing in memory (it's fairly short strings), and simply writing to text with updated int values at the end of a session. An alternative approach would be a single sqlite table that I update as the app functions.
I'm sure it's fine either way, but just out of curiosity, which would perform worse, reading/writing to sql table or text parsing?
As stated by #Rotwand, you should go for a database just for the whole abilities provided. Text parsing may be faster only if you only access to first/last rows, or maybe select data sequentialy in the order.
In other cases, trying to optimize text parsing will lead you to something equivalent to database, thus, no need to reinvent the wheel.
Text parsing (or serialization) may also be an option if you have specific needs (complex object structures, very few objects, ...) but database should still be a good thing at least to have more access options.

Should I use sqlite? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In my app i want to add a new feature that consist in having a list of object's bought by the user. So, when the user buy something he add's that object to the list. Later, if he starts the app again,there should be all the items added in the list.
The object will have some parameters (name, bought date, price, etc etc). My question is: is this a case to use sqlite?
If yes, In the activity with the list of the objects, everytime the activity starts I will have to load the table from database?
The answer to your first question is "yes". The answer to the second is, also, "yes".
Should I use sqlite?
Well, it depends on your preference and the scenario,
If you are using a webserver and updating the webserver, no need
to use a sqlite since you can ping a query to server and show the
objects for the list
If you are not using a webserver you can use Sqlite for this
scenario since you can perform all the
CRUD(Create,Read,Update,Delete) operations for the Sqlite
Advantages and disadvantages of using SQlite
Pros:
If your application gets closed the in memory data will be lost, but after that you will be able to restore the state from the database if you have one
Especially for the case of complex calculations it is good to store the result once in the database and not recalculate it multiple times on demand
The database will untie your UI from the internet connection and thus you will be able to display results even if there is not internet connection
Using database you will be able to fetch the updated data from a background service, without impacting your UI
Organizing your data in database usually makes it a lot easier to manage all the application data.
Cons:
Adding database will require a bit of additional effort on your side
Sinple Line :: Go for Sqlite solution

Storing data on Android for offline access [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
what are the best practices to save content data when the device is offline or when you have already downloaded some content that shouldn't be retrieved from server again?
Is SQLite the best approach to achieve this? If the information that I want to store is retrieved from an API as a JSON should I create a database structure to parse and insert it?
I know that the above are different questions but the purpose is the same.
Using Sqlite is a bad idea as it is extremely slow and takes up a lot of unnecessary space. When possible serializing objects or using SharedPreferences should be prepared to sqlite (unless of course you have a database structure). For caching and storing data pulled from the internet, I recommend robospice: https://github.com/octo-online/robospice. It's a very well done library, easy to use, and should be used any time you download data from the internet or have a long-running task.
I would say that it depends on the type of data you're saving. Sqlite is not always a bad idea. It's slower than storing an array in memory, but if you're handling a 500-entry address book an array is going to be a lot more clunky than a database.
Robospice looks interesting.

Categories

Resources