I've made an Android application which contains most used German words and sentences. The application contains a CSV file which stores all the data.
Currently it is working as expected but I want to ask if there is a better way to store such data directly in the app?
I'm also thinking about the ability to update the data via internet like adding new words and sentences.
Thanks!
Miretz
If you want to modify the content (update, remove etc.) I would suggest using SQLite DB which has a pretty nice built-in integration with the Android platform.
There are 2 types SQLDatabaseLite and SharedPreference. Major difference between both is that one is organized and the other not so.
If you need a quick use of a storage facility within your app for example changing text sizes between activity SharedPrefference works best for you.
If you have a complex database system where you need more than one data to be saved for a particular event SQLDatabaseLite is for you example of this is spreadsheet of data for customers; Name, Phone Number, etc.
Related
I am building an app include edit text and button. The user can put text in the edit text, then click button to transfer him to the browser.
So, I would like to create other layout as recent to store the text that the user entered on the edit text.
How I can do that? I need the logic or code that can help me!
Also, should I have create database to store the data?
Example:
enter image description here
You can store data in multiple ways, and you will need to understand what is right for your use case. You can store data in memory, by simply creating a List with your data type and adding to it every time user will click a button, but then it will not persist between sessions with the app.
If you want the data to persist, then you would need to use permanent storage, and there are a lot of options here:
You could use Shared Preferences
You could use File System and save the data to a file
You could use a database i.e SQLite, and store data there
You could use external server, and get the data through REST API.
Generally, there is a good overview of data storage in Android in the documentation which also have code examples.
Every option comes in multiple ways to accomplish it. There are built-in solutions, and multiple libraries to help you with this task, but first of all, you will need to understand what is the predicted usage of this data. I.E Should user have access to the data from another device? Should the data be available offline? Will data have complex structure? How the app can expand in the future? e.t.c.
Only by knowing this you can design how you will handle it.
If you need logic or code to create view, then you will need ListView, or RecyclerView, Adapter for handling the data, extra xml layout file for single item of your data.
I want to store multiple values (String, Int and Date) in a file via Java in Android Studio.
I don't have that much experience in that area, so I tried to google a bit, but I didn't get the solution, which I've been looking for. So, maybe you can recommend me something?
What I've tried so far:
Android offers a SharedPreferences feature, which allows a user to save a primitive value for a key. But I have multiple values for a key, so that won't work for me.
Another option is saving data on an external storage medium as file. As far as good. But I want to keep the filesize at minimum and load the file as fast as possible. That's the place, where I can't get ahead. If I directly save all values as simple text, I would need to parse the .txt file per hand to load the data which will take time for multiple entries.
Is there a possibility to save multiple entries with multiple values for a particular key in an efficient way?
No need to reinvent a bicycle. Most probably the best option for your case is using the databases. Look into Sqlite or Realm.
You don’t divulge enough details about your data structure or volume, so it is difficult to give a specific solution.
Generally speaking, you have these three choices.
Serialize a collection
I have multiple values for a key
You could use a Map with a List or Set as its value. This has been discussed countless times on Stack Overflow.
Then use Serialization to write and read to storage.
Text file
Write a text file.
Use Tab-delimited or CSV format if appropriate. I suggest using the Apache Commons CSV library for that.
Database
If you have much data, or concurrency issues with multiple threads, use a database such as the H2 Database Engine.
I have a bit of a rookie question regarding storage of map data i a java game. I'm making a 2d tile-based game, where each tile has an id (1, 2, 3, 4 and so on...). I currently store the game data in a .txt file, where each number is seperated by a tab. Therefrom i read it via scanners .nextInt.
This method works fine, but it seems to give me a problem:
Since the level file is just a normal .txt file it is easily edited by anyone. This means that the user could just change a few numbers in the file with any kind of text editor and thereby easily cheat.
How would this be avoided? Should i store the map data differently or should i use some form of encryption?
One solution to this would be to store the data in a database, such as derby. Once the game has been exported as a jar file the casual player will never even see the file, and if they do get their hands on it, probably wouldn't know what to do with it.
Here is a nice tutorial on how to set up and connect to a simple derby database.
http://www.vogella.com/tutorials/ApacheDerby/article.html
good luck.
Java has a Serializable interface that can be used to save java objects.
API docs can be found here: http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html
This doesn't make it impossible for people to cheat and change the maps just more difficult.
If you're really worried about it you could use some form of encryption or add a checksum to further prevent tampering.
I'm building a home replacement app. I need to store the ArrayList with the apps the user picked to show on the launcher in the internal memory. I mean the array mustn't be deleted when the app is closed.
I'm very close to finishing the app and I don't think I'll work a lot more on Java, I'm not a programmer so I just want the easiest way to do it. How can I store and retrieve an ArrayList in the internal memory?
Use SharedPreferenes to store and retrieve the arrayList..
Check this link..
Save ArrayList to SharedPreferences
You should store such data as Arraylists in the database and when you relaunch the app just fetch the data from database(SQLite) and display it to the user.
Heres a good tutorial on android SQLite.
Take a look at this link, for all the different data storage mechanisms in android. But for your requirement I would suggest using a db.
The easiest way is to use Java serialsation. It writes the content of an object to a (file-) outputstream. Thats a few lines of code.
a bit better (faster, less bytes, readable by other non java systems) is to uses a custom serialisation, using DataOuputStream. That creates a binary file in the format you define.
I have been wondering about this, which is why I have put off learning app development for so long. Let's say I was making a school timetable app, that all the user had to do was enter the name of their course, and then the app shows the timetable for that course..
The questions is can I get information from the college or do I have to hard code it into the database myself?
How does one get information to use if they need it?
Thanks
It depends. Does the college provide you an interface you can use? Probably not one that was meant to be used by a third party app.
If not, then you have to somehow get the information into your database. Either per parsing their online HTML schedules or inputing it by hand (obviously always one of the last options to consider).
If the college had a website that you could view, you could scan the page for class listings and pull that data in - but more than likely that sort of data will need to be entered manually by you when you ship the app.
If college is having its website and the website provides RSS feed for time table you parse that XML file and show the data which is parse or you can save the time table information of which course in the database and display that using cursors.