I have a product page with spinner. Spinner contains list of products. Dynamic views will be create by selecting product. No.of fields will be differ for each product. Fields may contain Edittext, Spinner. After user complete columns there is a save button to save filled details. Once user press the save button all fields value should be store in local.
I tried to save details in SQLite but sqlite only for structured datas. I am confused which local storage will be support for dynamic datas.
Please suggest any solution. Thanks in advance
You may serialize the result-object into json - and then store that json everywhere (sharedstorage, sqlite etc)
Simplest and fastest solution: you can have all the possible fields in the database and then store null values.
Best solution: Have multiple tables for all the different types of products that you can have and store the data there appropriately.
Related
I am currently developing application that store some trip's data on array. As we know in android development we can use hash-map for storing data into fire-store but that not fit what i need , it store the data without array index. is there any idea to structure the data as it shows on the attached screenshot. Thanks in advance
To store an indexed array of items in the field of a document, use an ArrayList.
In my grocery app,I was saving products selected by users in Singleton Class.Now according to new requirement, these products(cart) should be retrieved again whenever user reopens the app.
Class Product has many fields :
{
"imageDisplay",
"categorySpecial",
"_id",
"name_ch",
"name_en",
"origin_ch",
"origin_en",
"description_ch",
"description_en",
"specification_ch",
"specification_en",
"unit_ch",
"unit_en",
"priceOriginal",
"price",
"stock",
"sold",
"isOnShelf",
"processingPriority",
"imageCover"
}
1) My First question is should I just be saving all product field or just product Id.In case, if I save product Ids,I will have to retrieve detail of all cart products when app starts ,but If I save all fields of product then it will occupy a lot of memory.
Which one is the preferred way to save products?
There are 3 options as per my knowledge
1) storing in shared Preference
2) storing in File
3) storing in sql
You could also use a simple SQLite Database. Since you only need to store grocery items, I don't think you would need more than one table with 2-3 rows. Android has pretty good documentation on it. If you have any struggles with it you can ask here or see some step-by-step tutorials.
Android documentation:
https://developer.android.com/training/data-storage/sqlite
To retain the state of an app upon app death, SharedPreferences is to be used. If you need a database, you can use SQLite.
For your intention, SharedPreferences is the best as all you need do is to retain what the user sees before killing the app. Hence, all you need concern yourself are those fields in your data that are presented to the user (those data that users sees or interact with before killing your app) one of which may be id or origin_ch.
For database you need all necessary data saved but for SharedPreferences, you need only the data the user sees or interact with before the app death.
If you are storing Products in SQLite database better decision will be to store product ids in SharedPreferences. To retrieve products cart you first obtain ids from SharedPreferences and then find your products by that ids. Imagine the situation when product options changed - you will required to change both SharedPreferences and Database product instances stored, so just storing id's will be better decision.
I am making application to collect health logs for a research purpose. I wanted some architecture design advice.
My app requirement:
There would be various forms with numerous fields.
This data needs to be stored locally (next phase is to store it on server)
Also we could have new form as the user base increases
The user must also be able to update a previously entered log
Question
For eg :
Form 1 : (Name , Age, Sex )
Form 2 : (Name , Age, college, height )
The actual form has many fields related to health information
Since the data I receive from the user would have varied fields as above, how do I Store the data of multiple forms into the database. Also I want to add the functionality to add new forms to the app, thus making a database table for ever form is not a good idea (in my opinion). I was thinking to store the data as a JSON string in to the data base with the associated form ID.
Option 1. Store each field as its own column in the database, query the database for the appropriate fields to recreate the various forms.
Note - that changing the field value, changes the value for all forms, unless you specify different column names to save the data under for the different forms.
See tutorial on creating an SQlite database to get started.
Option 2. Serialize a hashmap and store the map as a blob in the database. Easy to add new fields without changing your database. Downside: Can't query for individual characteristics (age, sex, etc). When you retrieve info on a person, you retrieve all of it, and pick what you need. (simpler, but less efficient / robust).
I am going to populate data from server to a listview (endless). What is the best practice for doing this? Should I cache this data to local db?
Update: Usually list contains not much data about each item. But those item types (say it a "company info") I am also going to use for favorites which should always be stored locally. So I would like to reuse the same table for favorites and items temporally downloaded from server.
Firstly as per per your question please be specific about your requirement .
To handle data from server to listview .. The data that is obtained from server ( i.e parsed json , xml etc) need to sotred in some collection say ArrayList or Hash map etc.
These list can be populated from the above collections.
But if you intend to have permanent storage for the data in the app i.e offline browsing etc than you should save the data in sqlite db and use Cursor Adpater etc for showing the list.
So, the way you use the android recommended widgets and views depends upon the your requirement in mind + the optimized way to handle those things in efficient way.
I am making an expense log application. The user can create a log by adding a picture of an object and then add the price and some comments to it.
I would like to know if I need to use database to store that data or i can store it directly to the phone.
There are several ways you can store data in Android application: SharedPreferences, files, SQLite databases, etc. Which one you choose, depends on your requirements, amount of data you need to store, etc. I suggest you read Data Storage section in the Android developer's guide to get started.
For your case a databse is the best fit. You could put all expenses in a String array in the SharedPreferences but this would be horrible to use. You would always need to load all expenses to memory if you are searching for one and so on. A database allows searching, filtering and ordering through SQL. It is a bigger initial amount to create the Database but the management of the data will be much nicer afterwards.
Demonick is right about the images, only store the path to the image file in the database and then retrieve the images from there. If you are storing images on the SD-Card the user or other apps can access and delete them so don't count on them to be available later.