i have made application in which Homesceen stored username and password than redirect on second page .when i close this application or power off device than again click on application icon than i want to redirect on second page . so what can i do for doing this ? can we get power off functionality or anything else ? how to stored variable in memory of this application ?
You could used Shared Preferences to store your login and password :
The SharedPreferences class provides
a general framework that allows you to
save and retrieve persistent key-value
pairs of primitive data types. You
can use SharedPreferences to save
any primitive data: booleans, floats,
ints, longs, and strings. This
data will persist across user sessions
(even if your application is killed).
Related
What is the purpose of SharedPreferences in Android?
Why it is used ?
Where it want to be use?
Shared preferences is used to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
for more visit here
reference earlier answered
You can read the developer android site about SharedPreference to save light data till your application exists into user's device. It will remain saved even after existing your application.
Storage in android with SharedPreference
SharedPreference in android
Hope it will help you..!!!
SharedPreferences is used to permanently store preferences in key:value pair
SharedPreferences is accessible by all the Activity(ies) of an app. Other app cannot directly access the content of shared_prefs
App stores its data/preferences in the SharedPreferences.
E.g. Say in a game u can store ur score, game level, user name, no of kill, etc in the preferences; so that it is accessible all throughout the game; yet by that particular game only.
Game "Gold Miner 2" does it. It is only one example.
Svox tts save ANDROID_ID in preferences file;
You need to keep in mind that if u delete the app, all SharedPreferences will be deleted (/data/data//shared_prefs);
This will be an additional question to my previous question: Storing password for an offline app
If I store my password in a file in external storage and it's encrypted, is the file editable?
I'm just thinking for example, I set a pass "hello" and stored it in a file. Then to login, I will call that encrypted string.
What if you open the file where your password is stored and edit that encrypted string and save it and you try to login again in your app, will the "hello" still work?
Sorry, I'm kinda new to this thing.
Why don't you use SharedPreference for this kind of data saving. If your data is not quite big you can use SharedPreference for that. Save the data in SharedPreference so it wont be editable explicitly. And the data is only editable by your app. Documentation for SharedPreferences
The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
Yes, the file is editable. The only way you can make it uneditable is storing in internal storage using mode_private.
The encryption prevents people from reading what the password is and editing into a format readable by your application only.
I have an EditText field called ed. It will store some text that the user will need when the app is started again. I will need to save the text so that when the app is opened again it is back in the EditText field. How do I go about this?
SharedPreference is a way to go.
The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
Here is the example to implement SharedPreferences.
http://android-er.blogspot.com/2011/01/example-of-using-sharedpreferencesedito.html
or
http://marakana.com/forums/android/examples/63.html
or
One more basic thing you can look up is the example implementation given in the APIDemos of android. APIDemos sample application has all basic examples one need to know.
The most simple way would be to store it as key-value in prefs (putString/getString):
http://developer.android.com/guide/topics/data/data-storage.html#pref
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.
I am implementing CHANGE PASSWORD functionality in my app. I am not allowing the user to enter his username. I will be sending the data to local server. I have defined username edittext in one class. Now for password reset, I want to send only old password,new password and confirm new password entries to the server. I want the username to be fetched without users' knowledge. I learnt we need to use Bundle to pass values but it needs intent. I dont want the user to navigate from his class to another. Is there any other way we can pass edittext value of CLass A to class B without intents?
Would Shared Preferences help?
From official docs,
The SharedPreferences class provides a general framework that allows
you to save and retrieve persistent key-value pairs of primitive data
types. You can use SharedPreferences to save any primitive data:
booleans, floats, ints, longs, and strings. This data will persist
across user sessions (even if your application is killed).