0

I'm trying to save a variable to persistent storage (as described here) but the complier doesn't recognise the 'Current' member of 'Application' class. I'm trying this:

Application.Current.Properties["id"] = id;

but VS2015 assumes that 'application' is an instance of the 'Application' class, not the class itself. (the error given is: 'application' does not contain a definition for 'Current').

The instance is defined in a library module:

public Application Application { get; }

I've tried GetType() and MethodBase.GetCurrentMethod() without success. Sorry if this is basic c# knowledge that I've forgotten.

quilkin
  • 874
  • 11
  • 31
  • 1
    are you using Forms, or is this just an Android project? The link you're using is for Forms, but your replies below make it sound like this is an Android project. – Jason Nov 02 '16 at 00:34
  • Yes, thanks, this is an Android project. I did search for 'Xamarin Android persistent storage' but didn't notice that the info that came up was about forms. – quilkin Nov 02 '16 at 18:06

1 Answers1

1

Use the fully qualified type name including the namespace where the class is declared in:

Xamarin.Forms.Application.Current.Properties["id"] = id;
NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • Better, thanks, but still not there. 'Android.App.Application.Current.Properties["id"] = id' : now 'Application' is recognised as a class , but still no definition for 'Current'. Looks the latest update to Xamarin (which I just installed) doesn't have this definition, I can't find it in the metadata for 'Android.App' – quilkin Nov 02 '16 at 00:02
  • It's only available in projects that use Xamarin Forms. You don't use Xamarin Forms it seems. – NineBerry Nov 02 '16 at 00:12
  • 1
    Do you only want to target android? If yes, you can use the solution from http://stackoverflow.com/questions/26668509/how-do-i-use-sharedpreferences-in-xamarin-android – NineBerry Nov 02 '16 at 00:23
  • Yes, that's what I need, this is an Android project. I did a search for 'Xamarin Android persistent storage' but didn't notice that the info that came up was about forms. 'SharedPreferences' works fine; I only want to store one integer. – quilkin Nov 02 '16 at 18:09