I'm developing an App where the users must login to use it. I want the user login just the first time and session keeps active the next time the user open the app. The session must be closed explicitly by the user.
I have this on Android using Shared Preferences, I have a isLoggedIn boolean value that changes to true when the user login the app, and a validation in all screens. I also save the Username and the userId (to use it on the querys). When the user logsout, all data is cleaned.
I need something like this on Windows Store, I need to keep sesion active even when the user closes the app. Could any give me an idea?
Thanks in advance.
DataStore is a new and improved data storage solution aimed at replacing SharedPreferences. Built on Kotlin coroutines and Flow, DataStore provides two different implementations: Proto DataStore, that stores typed objects (backed by protocol buffers) and Preferences DataStore, that stores key-value pairs.
Yes, it is deprecated. Use the AndroidX Preference Library for consistent behavior across all devices. For more information on using the AndroidX Preference Library see Settings.
Shared preferences are not secure as we can simply view the data stored within the shared preferences and can easily access data within that file. To make the data stored in shared preferences secure we use encrypted share preferences which are more secure and the data stored in them is encrypted.
Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment. getDataDirectory() .
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.storage.applicationdata.localsettings?cs-save-lang=1&cs-lang=csharp#code-snippet-2
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a simple setting
localSettings.Values["exampleSetting"] = "Hello Windows";
// Read data from a simple setting
Object value = localSettings.Values["exampleSetting"];
if (value == null)
{
// No data
}
else
{
// Access data in value
}
// Delete a simple setting
localSettings.Values.Remove("exampleSetting");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With