I have an application which supports multiple accounts (max 8). These accounts are local to the app. Each account has the following parts
Name of Site
Site tel number
type of control
username
pass
Currently I plan to implement them by using shared preferences. I will define keys for all the elements of 8 groups and save/retrieve them using shared preferences. I would like to know is this a good approach or should I use another approach?
Thanks in advance
It is better to use SQLite database for implementing your requirement. The main advantages of using this is
1. Can check username and password in easy way.
2. Can add more users in future.
SQLite Tutorial
'SharedPreferences' are stored in the data directory for the app, but if the user has a rooted device, this file can easily be accessed and read with just a text editor.
For storing account information, you should look into using MySQLi and data encryption.
As you have limited number of accounts and just a few settings for your accounts, that will work ok for you as you have up to 40 settings to save. It won't cause performance problems and you can write some kind helper class to manage those shared properties easier.
You should think about whether you want to increase the number of accounts in the future. If this is the case, you should consider SQLite database.
Related
What could be used instead of Shared Preferences for storing user information? People say Shared Preference is not Secure.
You can use SQLCipher library for encrypted database or encrypt/decrypt values yourself with some key and store result in SharedPreferences. To store keys use Android keystone system.
If you are storing information in the users' device, no approach is 100% secure. You can hide the information in some ways (eg. encoding, encryption, etc) but still won't be 100% secure.
In order to make your information secure, you will need to store the information in a remote server.
Shared Preferences are stored as a file in the filesystem on the device. They are, by default, stored within the app's data directory with filesystem premissions set that only allow the UID that the specific application runs with to access them. So, they are private in so much as Linux file permissions restrict access to them, the same as on any Linux/Unix system.
Anyone with root level access to the device will be able to see them, as root has access to everything on the filesystem. Also, any application that runs with the same UID as the creating app would be able to access them (this is not usually done and you need to take specific action to make two apps runs with the same UID, so this is probably not a big concern). Finally, if someone was able to mount your device's filesystem without using the installed Android OS, they could also bypass the permissions that restrict access.
If you're concerned about such access to your preferences (or any data written by your application), then you will want to encrypt it. If you are that concerned about them, you're going to need to figure out exactly how much protection is necessary for the level of risk you see.
You can also use Database with encryption like whatsapp. Its a best way for security point of view. If you want you can hide the Database also.
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'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
I'm working on an application that requires I save a field between application uses, so that I can retrieve the data during the next use (ex. save username when logged in, retrieve it and pre-populate username field when application is next launched). I've looked around and found a couple ways to accomplish this goal, such as encryption & saving in a file on the local machine, and saving the value in the Windows registry. Are any of these methods better than others for accomplishing this goal? Any other suggestions?
You can store it using the Java Preferences API which will store a small amount of data in a system-specific way. On Windows, I believe it stores it in the registry, but on a Mac or on Linux it will be stored in a manner appropriate to those systems.
The data is stored, for the current user, under a key that is specific to the package of your class plus a string of your choosing. See the Preferences API Overview for more details.
I'm working on creating a checkbook app for android using a database to record transactions. The design I'd envisioned was/is to allow the user the ability to create different "accounts" (savings account, checking account, etc) under whatever name they choose and use that as the database table name. However, using preparedStatements doesn't work when I try to create a table. So I'm wondering if I'm going to need to sanitize the input manually or if I'm missing something. This is my first Java/android database program and I've got no formal education in databases so its possible I completely missed something. **edited to reflect more accurately what I meant by account. As this will be on an android device I have no interest in multiuser setup.
Probably, you don't need a table for each user. You should revise your database structure.