I am trying to build a logging in system (stored in online database) for Android by email and facebook. Right now I coded the logging in for Android by email, but I am wondering how I should best code the part to remember if you are logged in or not the next time you open the app.
Is the best way to do this to simply keep track of this in a shared preferences file with a boolean? And should I store this just by username and then just get all the scored points of this user from the online database? Is it necessary to encrypt this data to my shared pref?
yes,shared preference is preferred way to do this.And why only store username,i mean store all the data in shared preference and then fetch it from there.there's no point in fetching it again and again everytime from server unless it is updatable.
Related
I'm new in android, I am developing web application by android studio.
When user open application, there is activity login. User need input ipaddress of server, username and password before access application.
What I want to know, Is it possible to save ippaddress and other data to something like SEASSON/Cookies Web in Android Studio? So user only need 1 time to input data, store it and ALL activity inside application will get that data everytime it needed.
Thankyou my friends.
If you want to keep the User's Login data locally, encrypt the values and store it in Shared Preferences or in SQLite Database.
I think storing it locally is the best option because it wouldn't require your app to make network calls every time user opens the app.
Here are my suggestions:
1. If you have a web service, encrypt and persist the values securely to your web service via a post
2. Encrypt and store the values in shared preferences
3. Encrypt and store the values in a sqlite data base on the device.
I Know If the User have to Store UserName and Password then we can create Class and store the UserName and Password in Class. At get the data using SharedPreferences for that class.But That class store the data upto we can not close the Application. If we close the Application then data will be destroyed.
My Question is :
I Want to Store Data in Application if the User close the application or Restart the Mobile device. But the data are Store in the Class. How to perform this task. I am new to android. Please Help me.
You are new to Android. So, you should go through this link. You got these many Storage options in Android: http://developer.android.com/guide/topics/data/data-storage.html
In your case, You can go with SharedPreferences. Your data will be stored in key-value pair. And also, it is persistent storage.
I am developing a Restful Webservice using Eclipse and an android application. User logs in using its username and password on the android application which is checked against the database at the server side(using this web service).
Now, I want to maintain a session for which the user will remain logged in, that is, the user does not have to log in again and again whenever he re-opens the application.
How to do it? I searched on net but I could not find an accurate solution. Kindly help with the appropriate solution. Ask if more information is required.
use Shared Preferences to save session data .
there are good tutorials :
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
http://androidexample.com/Android_Session_Management_Using_SharedPreferences_-_Android_Example/index.php?view=article_discription&aid=127
This can be done in two ways. One is storing them in a global variables and second is storing the data in shared preferences. The problem with storing data in global variable is data will be lost once user closes the application, but storing the data in shared preferences will be persistent even though user closes the application. Here is the complete example:
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
I'm trying to build a secure remember me system that allow user enter in the app without insert credentials each time.
i found this:
Add a "Remember me" checkbox in whitch was used sharedPreference that seems to me are not te best solution because every rooted phone can easily modify that params.
what's the best practice to follow?
well the idea behind remember me is that you trade in their user name and password for some sort of auth token from your backend, and save that in shared prefs or SQLite. You SHOULD NOT be saving their username and password anywhere. You should be saving a token of some sort for them. if they dont have a token stored keep them at login, and if they do then take them to the main page and send that token to a backend to be validated, and log them out if it is not
You can save credentials in SQLite. Encode them and decode.
You can implement own decoder if you want and saving credentials in SharedPreference.
I know this topic has been discussed before on Stack Overflow. But there are still some things that are not clear when I read previous posts about it. So here they are:
I know that we use shared preference for small datasets and sqlite for large data manipulation, so if we just want to save a username and password should we use shared preferences?
Won't shared preferences be lost when user uninstalls the app? For example I download an app called abc and save my username and password. Then I uninstall this app from one phone and try to access it from other phone using the same username and password. Will this be saved using shared preferences or the data be lost?
What are the main reason we use one over the other beside large and small datasets?
You can think of the difference between shared preferences and an SQLite database in terms of data size but that isn't entirely accurate. A better way to think of it is in terms of the structure of the data you want to store.
Shared preferences can only store key-value pairings whilst an SQLite database is much more flexible. So shared preferences are particularly useful for storing user preferences, e.g. should the app display notifications etc. Whilst an SQLite database is useful for just about anything.
Both data sources are local but something you should be aware of is the ability to backup your application data to cloud storage that is linked to the user's Google account. This makes it much easier for your users to change devices and for their applications to easily transfer to the new device. For more info take a look here.
In the situation you described about you will lose the user name and password in both situations. The data is stored on the phone, when you uninstall the application, the data that some with it will also be lost. The user will have to re-enter this information.
You can save the user name and pass in either the shared Preferences or a DB, that is personal preference. Just make sure you lock either down, i.e. don't share the DB or Shared Preferences that you keep this information in.
As for the difference... shared Preferences should hold well... shared Preferences... here is an example:
If I create an option to change the background color, I will store all available options in a DB that can be loaded into a adapter view for the user to choose from. But I will store the color that they have selected in the Shared Preferences. This way when the application load I can get the Shared Preference value of the background color that should be used.
SharedPreferences is used for just that, storing user preferences shared application-wide. You can use it, for example, to store a user's username, or perhaps some options he or she has configured in your app in which you want to remember.
SQLite is a relational database. It's used to store your application's data, not preferences or configuration information.
Both are stored locally on the device.
1.SharedPreferences stores only Boolean, int, float, long, String five kinds of simple data types, such as can not be conditional query. So, whether SharedPreferences data storage operation is how simple it can only be a supplement of storage, but can not completely replace other data such as the SQLite database is stored.
2.SharedPreferences based on the XML file to store key-value key used to store configuration information(mainly user preference for your application).
3.Sharedprefrece just like cookies in web which store some basic information at client side.
both store their data locally, so uninstalling the app will delete both. other than that, SharedPreferences is easier to program, and you're right about the data amounts.
In general, shared preferences should be used if you want to allow your user to directly manipulate certain data fields. Shared preferences are basically user preferences; if you would like the user to reconfigure the app to behave in different ways, you should expose that functionality as a shared preference. On the other hand, the SQLite database should be used if you want to limit the visibility of the data to just the application, if you want a stronger guarantee that the data be persistent, and if you want the application to behave independently of what is stored in the database. Of course, you can use both in one application.
Shared preferences and the database are part of local data that the application stores. If you uninstall the application, both of the data stores will be removed.