using arrayList with 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 4 years ago.
Improve this question
I'm writing an application with an internal database.
I'm getting data on database with the arrayList because I have to get different type of data. My question is: are ArrayList the best solution to get data from this database or there are others method to do that?

An ArrayList is one way of reading data from a database. It will be convenient to store all the info from a column in an ArrayList, such as an ArrayList for the name column, or age columns, so on...
Another data structure that you may consider using is a Map such as a HashMap or a TreeMap. This will not only enable you to store the data values but give it a key as well, this way you can refer to the value by using its key. An example of where you may use this if you want to retrieve the names of a person and their age. By using a HashMap, the key could be the person's name and the value could be their age. This would make it easy to retrieve the person's age based on their name.
Maps are used to put information into a database, as can be found by this documentation from Android Developers. The Android Developers documentation also shows that Lists can be used to read data. Essentially, it comes down to your uses. If you are reading multiple columns, you may consider creating multiple Lists whereas if you were reading from two columns, such as name and age, you may consider using a HashMap that way each age corresponds to a name and it is easy to retrieve that age from the name.
I hope that this answer has given you some insight and input into which data structure you have decided to use, but ultimately, it is your choice.

Related

Should I use arrary or sqlite database? [closed]

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.

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.

How can I create a history of previously created TextViews in an Android App? One that the user can access

I have a simple simple app, that simply takes a user's question as input, and creates a long string containing: the original question, and a randomly generated answer. This string then gets displayed as a TextView (I'm sorry if I'm not describing this correctly).
What I would like is to have a tab or page where instead of asking a question, I can see all the previous questions, and select one to see the same string that contained the Question and the Answer.
I don't even know how to phrase this to get useful results from searching. I'm really at a loss here, and anything would be a help.
Thanks!
Store your results in a database.http://developer.android.com/training/basics/data-storage/databases.html
Make a table with the questions and answers as two columns, and keep saving each entry into that table in the database.
Note: Check whether or not you want to make the question as primary key, according to whether you want questions to have more than one random answers.

advice on how to efficiently store images in Parse DB

I'm currently building a reasonably big Android app and I was wondering how I could best store images for my tabels. Currently I have a 'Vacation' table and that table had 3 columns, allowing each vacation to have 3 images.
Currently this works, but it isn't ideal and it should be changed to a more versatile number.
I've been thinking about how to do it and I've come up with the following idea, though I'm not sure if it's efficient. I added an extra tabel, called 'Image', which contains an 'ImageID' (string) field and an 'Image' (file/picture) field.
Now I'm not sure how I'd best link the images of a vacation to its vacation. I've thought about adding an attribute to 'Vacation', which would contain an array of ImageID's. The downside of this would be that it'd probably require an extra search query, plus I wouldn't explicitly use Parse's relations in the table.
Does anybody know how I can solve this problem?
In the Parse Data Browser Online:
I would add a column to your Vacation class in Parse - we'll call it "Images". When creating this column, select array as the data type. With arrays you can store almost any type of data in Parse - including images.
In Your App:
What you will need to do in your app is create a ParseFile for each image, and then put all of those images into an array (I'll call it: myArrayOfParseFiles). Then, get the Vacation ParseObject you are working with (I'll call it myVacationObject), and assign the array to the "Images" column in your object like so: myVacationObject.put("Images", myArrayOfParseFiles) Once you save your object all of the files will automatically be transferred to Parse, and you can see them in the column in the online data browser. You can store almost any reasonable amount of pictures in these arrays, and you can delete/add/modify them as much as you wish in your app and in the data browser. I am an iOS developer, but the ideas are the same and I tried to reference the Parse Android Docs to make my answer apply to you. Please let me know if you have any additional questions. Good luck!!

What should I do add new table to existing database or make new database? [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
I am trying to write an android application. My application reads some information from database and shows it.
Now I need to make the app personalizable for end users. For example, allow the end-user to bookmark a page or a line of text. For this what is the best idea for changing or modifing the database ?
Should I make new database and put a table for bookmark on that or add a table for that to my existing database?
This really depends on your use case and what you mean by "end user". If you intend for different users to be able to sign in on the same device, then you might create a separate database for each user. If that's not the case and the "end user" is really just whoever is using the device at that particular time (no authentication required), then you could simply add a table to your database.
Adding new database is something you will need to use if you want to access some data before logging-in by some user to your main database, so you don't need that!
I prefer to add a table to your current database with a structure like this:
create table tblBookMark(
Bookmark_ID int primary key,
Bookmark_Name varchar(128),
User_ID int --you can add a foreign key to users table here
);
I hope this helps ...
I don't think you need multiple database for a mobile application(never even heard of it). It will be unnecessary complexity for to simple a thing.
Multiple databases are normally used in scenarios where you have to store large amount of data from different sources and/or different physical locations for large applications.
Adding a table with proper structure(columns) should be more than enough.
A Database Creation is not a necessity. You can just store the Table ID Value with respect to the BookMark and maybe store it in SharedPreferences. So you can access the information from the same Database based on the User Preference.

Categories

Resources