I'm currently developing an app that lets you create and save excercises and routines for the gym. I want the app to come with some example excercises and routines and also to give the user the ability to add his own.
The thing is, I know I can use "getFilesDir()" and save it in the internal memory, but if I do that, how do I put my example files also in the internal memory? I don't think I can do that without creating those files by code everytime the app runs. I've also tried putting the example excercises in "res/raw" but then the ones the user adds go to a different place and I don`t know if that's good practice, apart from just how annoying it is having to read them from different places.
Where would be the best place to put those excercises and routines files?
Thank you very much!
The best practice is to store data inside "Sqlite Database".
"Sqlite Database" is the internal database that android provides to store data locally and is easy to use.
It's queries are easy to implement. It is more easy to work on, if you have worked on any database before. Just create a "Database Helper" class and initiate inside the activity where you plan to store data.
Many big applications like "whatsapp", use this database to store data on user's device.
The plus point of using "Sqlite" is that, you can iterate through each and every data easily.
It is quick, easy to work and is also a good programming practice. It is also secure.
While using a sqlite database for managing your app data is the traditional
approach, there are also alternatives to it. Realm is such an alternative. You can check the comparison with sqlite and see if it meets your need.
https://realm.io/
In Android development, you can store locally and as well as remotely. This link will walk you through all possible ways to store data.
As per your requirement, I would recommend you got for SQLite Database provided especially for android as it is light weight. Sqlite queries are straightforward and easy to use with some APIs comes with the package. you can start with this link with Sqlite.
I suggest using Firebase to store your data. Not only it is online and realtime, it can also work in offline mode and sync later. Because you're developing a gym app, why not give it an online or offline capability? I think users prefer it that way. You can check it at firebase.google.com
Related
I am just starting to learn Android Development. I have to develop something similar to a Log APP where the user can save information.This is student project, so I don't have to use Users/Passwords, instead I am allowed to save the info using the Local Storage of the device.
The problem is that I will need to extract that info into a CSV file, and I am not sure if using Local Storage is the best option.
Which option do you think is more efficient?
Which one do you think is less complicated to use in this case?
Thanks in advance!
You probably wanted to use Room for it is the official Android Database framework and the learning curve is quite easy. It even supports other Jetpack libraries such LiveData to make your Android development far more easier.
Use SQLite. You can query the data from the database and write it to a cvs file upon need.
Definitely use Sqlite, and not raw sqlite but use instead Room. Room is architecture component by android and is actually just one layer above sqlite so it is easier to use and removes a lot of boilerplate code. For storing really little things like login information you can use SharedPrefrences. Here is documentation about Room I suggest reading it.
I'm just getting started in android studio and app development overall. I've done a few tutorials to learn the interface and basics for Android Studio (activities, textviews, buttons, etc) and I've taken a college course in Object Oriented Programming in Java. Now, here's what I'm trying to do:
I'm making a very basic app that's meant to help the user budget their money. The app "acts" as your account and you add the amount of money you've recently been paid. From here, you can allocate your money to savings, checking, and so on. The data I need to store would be the numbers representing dollar values, the different allocations the users made, and the respective dollar amounts to those allocations.
I've managed to contain the data relatively fine within the Java data structures (I developed some algorithms in eclipse to get started). Do I need to serialize this data? Or try writing it to a text file? I've looked around for some tutorials and most low level ones are confusing or require advanced techniques with SQL. I'm interested in simply locally storing just as you would with a to-do list app that keeps record of tasks you entered.
Any and all insight is appreciated.
If I were you I would go the sql route. It's really not hard to get started with sqlite for android. If you haven't already seen Google's own tutorial on the subject, check it out here.
That said though, you can also look at the other methods mentioned here if you feel a database is overkill. Realistically the other choices would be internal storage or external storage if it's something like a todo list. Shared preferences are most often used for persisting user settings.
If you choose to go the file route and don't want to save the data as something like a csv then you need to make your java objects implement the Serializable interface and write them to the file with an ObjectOutputStream.
For example:
FileOutputStream fos = new FileOutputStream("/some/file/path/filename.ser", true);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(yourSerializableObject);
First important thing is that Activities, TextViews, Buttons and other view components are not part of Android Studio. They are part of android framework. Android Studio is IDE as Eclipse, NetBeans and etc.
Regarding your requirement, there are more ways of persisting data in android. You can use files, SharePreferences and sql (sqlite).
Please take a look at following document:
https://developer.android.com/guide/topics/data/
Also i would suggest you to follow Google android official documentation.
https://developer.android.com/guide/
Best Regards,
Milan
There are several ways to store your data locally on the device:
SharedPreferences - usually they are used to store app settings (Such as first name, last name, etc.).
Databases - used to store structured data, best solution when app needs to store large amount of data. Also, thay has powerful and flexible mechanisms of read/write operations.
Files - Not the best way to save structured data, no build-in mechanisms. Also app needs additional permissions to write/read operations (if you decides to save data on external storage), which can be denied by user(if your app is targeting api 23 and greater you should use runtime permissions)
The most effective way to store app data in your case is databases.
Google has developed Room Persistence library, which provides abstraction level over SQlite and makes all things simple and easy to understand.
Here is a nice example on Medium, which provides easy to understand tutorial for Room Persistence library.
I don't know if this is a super noob question, but I'm currently building an app from scratch with the knowledge i've gained so far, and I'm making a "Notes" app where You can create notes, delete, edit(update), etc etc.
The question I'm having is that I know I can use a database to store data from my input, and I know i can use A Database to save, open the data, but Just incase, does Java have a LocalStorage, like JavaScript/JSON where you can save things and open them up later?
If there is LocalStorage for applications to save data, and open it up after running again, what would be some good resources to read about it and learn it so I may integrate it into my application?
If there is no localstorage, I wan't to be able to perhaps allow the user to add images when creating notes, how would I be able to do that using a database?
As far that I know of there packages that allow you to store data as you intend, but following on your next question, you could possibly store the address/file name of the image you wants to add to the database. You could then use it to retrieve the image file and display it.
If you have any questions on image implementing images in java, reference this documentation and tutorial
If you have any more questions on working with databases, reference this documentation
I hope this helps.
I'm making an app that will be using few hundred database posts from a sqlite database. I will not be adding new data during the lifetime of the app (unless I update the whole app).
I might end up using a static xml for the data, but I need to flag posts, so I guess a sqlite db would do the job best. I know how to implement it and I've released apps using sqlite before...
But my question is. How to I best populate the sqlite db the first time the app runs? Should I just bring in a file that I use as a resource and then copy to the apps space? What's the best/easiest practice?
The simplest solution is to use SQLiteAssetHelper. You basically drop your SQLite database into your project's assets/ directory, and use SQLiteAssetHelper in lieu of SQLiteOpenHelper. In addition to the sample code up on Jeff Gilfelt's GitHub repo for the library, I have a sample app demonstrating it as well.
I consider myself an accomplished programmer, but I'm relatively new to Android App development. I'm creating an application that will store information into the SQLite database used in Android. What I'd like to be able to do is be able to take a query of that data and export it either as a file of some sort or just send it to another iteration of the same application on a different phone. Then be able to have that phone import the same information into its own database, seeing that the information should line up correctly as long as it keeps it.
Can anyone provide some good starting examples of how I would best go about this and/or tutorials on how to go about doing it? Right now I'm just not sure how to get started and I could use some help to push me in the right direction, so I'd really appreciate the help.
Thank you ahead of time to anyone who replies.
and export it either as a file
depends on what kind of data you have. You can write any kind of text-based data using a RandomAccessFile for example.
send it to another iteration of the same application on a different
phone
You will need to have your own backend to do so. You could identify the target device by using GCM