Should I use arrary or sqlite database? [closed] - android

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm seeking assistance on a APP I need to create. I don't have no experience with android app development but, I'm studying and practicing.
I'm trying to build an app to record payments from a list of customers and print a receipt when paid. I download a list of customers with pending balance, using json array into android. Now, I'm confused, don't know if I should use arrays or a database to store the list, since I need to update (upload) later to the server. SQLite seems like an option but, I have to download the list every time user is connected to WiFi.
I guess I have to store the payments on an array and flush it once uploaded.
Can you please tell me what would be the best option for the tasks I'm trying to accomplish.

It depends on your use case. Arrays and sqlite can work independently or together.
If you are going to upload the data instantly after downloading within the same session, then you can keep it in the Array and upload it after what ever you need to do with it. Keep in mind that Arrays will be kept in memory and depending on where you are keeping the array object, they might not persist through the life cycle of an activity or the life cycle of your application.
SQLite on the hand writes data to disk, so you will be able to persist it even after user has backed out of your application.
...since I need to update (upload) later to the server
Based on the above, it seems like you should persist your data on disk. SQLite is one of the options for persisting data. Have a look here to see what else is available for persisting data.
You can load up any persisted data into your array and upload it after you have processed it.
Hope this helps.

Related

How to reduce firebase realtime database download cost? [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 2 years ago.
Improve this question
Will making 2 database in firebase realtime database help to reduce cost and increase daily download limit of 360MB per day?
The simplest way to reduce the cost is by reducing the downloads. You can do that by caching the data on local storage as much as possible and continuously sync sensitive data.
While reading different articles, one article caught my eye. I'll summarize my findings and also add the link to the article.
Optimizations Possible:
Optimize serialized data saved in the database, this can be achieved easily with GSON, a library to handle JSON data that allows changing the name of serialized entities with annotations. (There are many other libraries that can do the same) GSON #SerializedName
Implementing a memory cache that is kept only during the life of the App. This cache works as follows:
User opens the app and goes somewhere in the app where any kind of favorites is listed, let’s say Bus Stop favorites.
The App requests to the memory cache a list of Bus Stop favorites but as the App has just been launched it returns null.
Then the App requests to Firebase only the node containing Bus Stop Favorites, which are downloaded from the internet and then billed once.
A copy of this favorites is saved in the memory cache.
User plays with favorites, adding, removing or editing them.
Every time a modification is done the resulting favorites list is saved in the memory cache and also sent to Firebase (because uploading data is free).
Now the user can leave the App, and unless it is explicitly removed from the recent App stack by the user or killed by Android, the user can come back to the App and continue playing around with the Bus Stop favorites without incurring in extra billing.
Link to the article mentioned.
Hope this helps!!!.
try to derive data from other data (for example if you have a voting app, instead of storing the number of people that voted, the number of people that upvoted and the number of people that downvoted, you can store only the upvotes and downvotes and do maths to calculate the total amount of people who voted)

How to make MCQ test functionality that loads data from server

I am working on learning application. I want to add MCQ test functionality in my app. I want to load data from the server when the test started. and it will not call to the server for each question because it will slow down test process. I want to load all the question when the test starts and a new question will appear only when clicking on next question button. There will be four option in each question so at the end I want to send data to the server to verify the answer. I actually confused in what should I used to save question in internal memory. and then their answer to submit to the server.
Android developer guide has an explanatory list of available options for storage that you can leverage. Since you would want to keep this information secure. I suggest you should use one from the list below
Internal file storage: Store app-private files on the device file
system.
Databases: Store structured data in a private database.
Although a lot depends on the size of data and other specifics of your use case.
Based on the discussion in the comments. Here is a cool answer to the same, i.e serialize/deserialize the objects.

What is the best way to display a large amount of different information 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 6 years ago.
Improve this question
I am currently creating an app that is a guide for a game which involves the user navigating through categories and a large amount of information being displayed. For instance, if I wanted to review information regarding a specific weapon, I may navigate through Items > Weapons > Ranged > Bow. What would be the best to to set this up so the app would run smoothly? I may have up to 100 of these different items the user can view.
The two current approaches I am considering is either making a local SQL database of all of these items, and then having one activity that pulls from the database based on what the user selects. The other being to just make string resources and then load those resources depending on what item the user selects. Any opinions or insight would be much appreciated.
I am not sure about string resources but if you are doing "read only" operations on the data and not saving any user input I would suggest NOT using SQLite. The problem with SQLite for this use is that you will have to create the tables and populate the database programmatically the first time that the app is run. (someone correct me if there is another way to do this) Basically you will end up writing all of your information as strings or reading it from a file on the device anyway, it will just get inserted into the database and be accessed from there every time after. Another drawback is that every time you want to update the information in the app you will have to add rules in the "onUpgrade" method of the database handler. Accessing the data from SQLite will be faster than reading files but IMHO it is a way bigger pain than it is worth for just read operations (unless you have massive amounts of data.. "massive" in the computer world happens to be pretty darn big).
I would probably store the data in your own files (XML, JSON, or just plain text) and put it in the assets folder. Using a nice folder structure and good file naming in there would allow you to add new information without having to change your program.
Another option is to build a web database, pull the information from there, and save it to the local SQLite database when there is an update to the information that you saved online. This makes it easy for you to make revisions to the content without having to send out an app update but takes quite a bit more work
The Content Provider is the prefered way to store big data on the android platform and fortunately many tools are available to do the hard work for you. With that said I would hardly consider 100 a large amount of data even on a mobile device. Will the data change? In other words is it static or dynamic? I recommend the Content provider but you could use shared preferences, a resource file or even hard code your values.

Live Search in Android [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the following task to do, I need to build a live search from an endpoint.
Now, the thing is I know how to do it but, what I don't know, is how to do it efficient. The small app should do the following:
Live search from a specific endpoint - a list of over 2000 objects in a json request.
While loading, the app should display a spinner.
Refresh the autocomplete list view.
The only solution I know is the following:
I add a menu to the action bar where I add the search view.
Inside the activity I will have a fragment with a list view (better when I want to add some clicking on the items), and when the user searches for something (e.g, "around, "a" first, then "ar", etc) then a new request to the server will be made and all the objects that start with "a" will be loaded to the listview and from then on autocomplete will do its work.
In this way I need to load all the data that contain "a" and filter from there.
Now the problem for me is that I need to parse every time the json file, and it is possible I only need 3 records.
As an improvement, I thought of somehow filtering the json big file and retrieving only the json file that I need, but I am not sure if this is possible and if so at what cost.
Does anyone know a better solution?
Since you can't change the server-side component, you'll have to make your client smarter.
The way to go here is (as #pskink suggested) to store the data locally. If you make a single request for every entered/deleted character in the search-view, you're practically DOSing their server. Also, this will be slow.
The challenge is to cache the data locally but keep it "fresh" enough so that it doesn't divert to much from the data on the server. Implementing this is harder than it sounds.
I would suggest loading the entire JSON from the Backend as soon as the activity opens. Depending on how big each individual entry in this list is, you might get away with keeping them all in-memory and filtering on that (i'm thinking a Tree might be a good starting point).
If you get any performance or memory problems with this solution, I'd suggest moving the data into some kind of database (it doesn't need to be SQLite, Realm might also be interesting). The same challenge applies for keeping that data up-to-date, of course.
Since you said they told you, I guess you're working with the people behind the server-component. In that case, I have found the best approach is to implement a solution that works (any of the ones above) and show it to them. If it's not fast enough for them, make suggestions:
They could give you an API to get only the new/changed entries since a given date (so you can just update the database).
It might also be possible to make a hybrid model: Filter on your offline-data first, but also make a request to the server (with a filter-parameter or something) and mix the resulting data. Indicate to the user that you're in the process of fetching more "up-to-date" data, but show them the results you already know. This might not work well if entries are removed frequently.

Best way to store and retrieve data locally 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 7 years ago.
Improve this question
I am developing an android app which handles a lot of text. I'm confused at the data storage and retrieval, Which one should i use for faster data retrieval? Sqlite or file storage (json files, separate file for each category ). First I thought about sqlite because it is more easy to manage data, but it will take sometime to create tables with almost 1000 rows in each table or i have to ship the database with my app and it will increase the download size and then i thought about file storage. Which one should i use, sqlite or json file as the data creation is a one time process an the rest is retrieval? Can anyone suggest a better way, i'm really, really confused.
Assuming that the table creation only happens once when the app is installed, then unless the table creation is very, very slow you can simply do it at app first install and include some appropriate message to the user on the screen.
Ideally, if your app can do other useful things without using the data then you can let the user use other parts of the app while the table creation completes in the background.
I have found from past experience that creating very large simple tables is actually very fast, but you would need to test to see how long your examples take.
Note also that you have the option, through the onUpgrade method of the SQLiteOpenHelper, to only modify the parts of the database that you need to at upgrade times, so you may not have to recreate the full data base when installing new versions of the app. This also includes mechanisms to avoid delaying app startup by deferring the updates until the database is first used, although that may not be what you want in this case.
If you have a lot of text and data, use greenDAO. It will handle your SQLite related stuff. It's a bit confusing at start, but once you tried it you will never use SQLite on Android without it:
http://greendao-orm.com/
Some interesting links:
http://developer.android.com/guide/topics/data/data-storage.html
http://developer.android.com/training/basics/data-storage/index.html

Categories

Resources