I am trying to do an eclipse java android app using internal storage.
It is a notepad. What it should be able to do is write and save notes, search for them an edit them.
the most similar application of what I need is this:
http://developer.android.com/training/notepad/notepad-ex3.html
but I dont know how to modify if to use internal storage and not external, i also found this file that allows you to read and save in internal storage
http://www.androidaspect.com/2013/09/android-internal-storage-tutorial.html
but now i dont know how change the database for the inernal storage
Okay let's break it down. You want to make something that will let you take notes. Fair enough. You need the kind of storage that will make retrieval and insertion easier.
Let's start with a single text file that you store somewhere (internal or external). If you use this approach, inserting and deleting data becomes difficult because any changes will require you to make changes to the actual text. Not to mention, you will need to format your notes in a way so that you can differentiate one note from another.
Okay, so will using multiple text files solve this? In a way, yes, but you can go for a better approach using SQLite.
SQLiteDatabase has methods to create, delete, execute SQL commands,
and perform other common database management tasks.
SQLite seems like the prime candidate for your storage because it makes CRUD (Create, Read, Update, Delete) easier. Instead of trying to modify the code, start from scratch.
Have a look at this tutorial https://www.youtube.com/watch?v=j-IV87qQ00M
Related
I am currently developing a program in Java using NetBeans that manages expenses. In this program I used MySQL to store data. Now I want to ask that if I give the program to one of my friend, he would also have to install MySQL using the same password that I used. Is there a way in which he will not be required to install MySQL?
Now suppose if my friend already has MySQL, but with a different password. My program would not work in that case, and it would be hard to replace my password with his password in the code. Is there a way to make the program run on his PC?
Earlier once, I have used an Oxford dictionary program. That time I did not have Microsoft Access installed. When I installed Microsoft Access I came to know that all the words of the dictionary are stored in a Microsoft Access file. How can I do this? I.e. how can I use MySQL/Microsoft Access to store data without the need to install either of them?
You can use an in-memory database like H2 Database if you don't require a large amount of data
But I think you should make your db connection configurable by using a properties file
If you want everyone to be able to use the database, you need to run it on a server that people can access through the internet.
However if you don't care about them using the same database and just want them to use their own, you could for example create a small file named "config.ini" or something like that and put the login information (like the password) in there.
Then just read it in your code and use the info you read to log into your database.
That way, every new user will only have to change the config.ini file without ever having to touch the code.
The best solution in my opinion would be SQLite as it is light, and data can be stored locally in a desired location in a single file. H2 is more likely to be a developer tool.
This solution does not require additional software to be present on the user machine. Of course it has its limits, but as a simply storage for program dynamic data it is a good solution. It is worth mentioning that Android applications also can store their data in LiteSQL. It is a bit different approach there, but the principle stays the same.
I've had a look around and haven't been able to come up with an answer to my issue.
I'm creating a fitness app and it allows users to save different workouts for future use. All the information is saved in txt file on internal storage. I'm trying to now implement a feature to be able to edit these workouts, so my question is:
What is the best way to edit a .txt file in android?
Should I just delete the old entry and save the new one in its place or is there a better way?
You can only append to a text file (add to the end); any other edit requires that you load the full file in working memory, modify it, and save it a new file (possibly overwriting the old one).
If this sounds like a bad idea (because the files are large and complex) then perhaps you should be looking at using SQLLite facilities which are standard android libraries and designed relatively simple record keeping tasks of this nature.
Unless your data is extremely unusual the SQL path will make for easier, clearer code in the long term.
Using SQLite database maybe the best way of saving data for different users. And if you want to edit a text file, you can load the full file in memory and rewrite the file after modify the content.
is it possible to use
Android's Backup Manager
to backup a minimal file
(A text file with 20 words?)
I can't quite understand if this is possible and how to do it. ..
As you can read at http://developer.android.com/guide/topics/data/backup.html you can save any type of data, including files.
Also take a look at http://developer.android.com/reference/android/app/backup/FileBackupHelper.html
If you are using the original backup APIs, you probably just want your BackupAgent implementation to extend android.app.backup.BackupAgentHelper, and then use a FileBackupHelper configured for the file you want to keep backed up.
https://android.googlesource.com/platform/development/+/master/samples/BackupRestore/src/com/example/android/backuprestore/FileHelperExampleAgent.java is an example of using FileBackupHelper for a single file. There are other example agents in that same sample code directory that show other alternatives for keeping data backed up.
On Android 6.0 (Marshmallow) and later, there is a new file-based backup API you can use instead that requires much less code in your application, possibly none at all. Take a look at http://developer.android.com/training/backup/autosyncapi.html for an overview of how you can use this new facility to get automatic backup of a file without having to actually write your own backup agent.
What is the best way to store a data set locally on a mobile device for further processing in Java?
The data set is going to be retrieved using SOAP and will consists of about 50 to 100 'objects'. Each object is like an email thread - main message followed by several updates (mainly text, occasionally graphics).
Expected actions on the 'objects':
read
add new update / send an update to the server
change status / send an update to the server
Is it better to operate directly on an xml file, implement a local data structure or perhaps use a database of some sort?
Target devices: Android & Blackberry. I would like to keep the solution as generic as possible to make it easier to reuse parts of the code the mentioned platforms.
Many thanks, Luke
It depends on you:
If you want something fast - use SQLite database or Store it in XMl File.
If you want something easy to implement (but slower) - use SharedPreferences
If you are thinking about to use SQlite or Xml file than i will suggest you to use SQlite database because you need to perform such operation on the data.so reading from xml file and again writing it to file will be little slower than SQLite database.
Hope this helps.
I am collecting data from a website and trying to save it to a database (or something similar that is very accessible) rather than having a heap of files on my desktop or in a folder.
There are many pages that I need to look at (1900 to be exact). I want to save time in getting this data, and decided to make a Java program to do this.
This is basically what I am trying to do.
Visit the webpage: www.TestWebsite.com/items/0
Save the (Name, Description, Image(png)) into one array/class to a Database.
Repeat until I get up to: www.TestWebsite.com/items/1899
I want to be able to access this data offline without having to need to go online to view it.
Any ideas on how I should start. I have made a basic webpage viewer, I am just missing the step in between saving the strings and images to a database.
I appreciate any help!
Actually just did this the other day. I used jsoup to scrap the webpages I needed and wrote to my local database. awesomely easy framework for webpage parsing.
It's fairly straightforward, but you'll need to learn a little SQL if you haven't already.
You'll also have to pick a database platform - I'd suggest SQLite for such a purpose, since the data is for personal use and it's lightweight and easy to set up.
Here's a tutorial on using JDBC (Java Database Connectivity) to talk with a SQLite database: http://en.wikibooks.org/wiki/Java_JDBC_using_SQLite. It goes from setup to inserting data, so once you've completed that it should be straightforward to modify your webpage viewing code to grab the data you need and shove it into the DB.
Good luck!