Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Something like Android-SharedPreferences on Windows Store Apps?

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.

like image 876
josher932 Avatar asked May 23 '14 15:05

josher932


People also ask

Is jetpack DataStore a replacement for SharedPreferences?

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.

Is shared preferences deprecated?

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.

Is SharedPreferences secure Android?

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.

Where are SharedPreferences stored?

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() .


1 Answers

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");
like image 76
L.T. Avatar answered Sep 19 '22 11:09

L.T.