0

I'm creating an Android application in Xamarin with C#. I've got one activity that is called every time a button is clicked. The content changes as it should do but every time the activity is reloaded my custom List is empty again. I want it to keep its values so I can access them on the second screen.

This is my list:

public List<Screen> ListScreens;

This is how the Activity is called:

saveButton.Click += delegate {
    if(ValidateScreen()){
        SaveData();
        Intent intent = new Intent(this, typeof(MainActivity));
        intent.PutExtra("CurrentScreenId", CurrentScreenId + 1);
        StartActivity(intent);
    }
};

Do I have to pass the List with the intent or is there any other way to access it in every activity?

Tom Spee
  • 9,209
  • 5
  • 31
  • 49
  • For me, in Android, I'd use a singleton class. – ChiefTwoPencils May 08 '14 at 07:50
  • I never used a Singleton class before, I've tried it with the answer of [this](http://stackoverflow.com/questions/12585720/how-to-use-the-singleton-pattern-in-an-android-project) question but the error I get says that `AppManager needs to have a public default constructor.`. – Tom Spee May 08 '14 at 08:20
  • My C# is really rusty, but I'd say you'd probably have to do it more like [this](http://stackoverflow.com/questions/2550925/singleton-by-jon-skeet-clarification/2550935#2550935) than like in Java/Droid. – ChiefTwoPencils May 08 '14 at 08:33
  • Can't get the Singleton to work, can't understand it is so hard to pass an object. – Tom Spee May 08 '14 at 11:33
  • Maybe [this](http://forums.xamarin.com/discussion/11921/simplest-parcelable-way-to-pass-complex-and-list-datas) then??? – ChiefTwoPencils May 08 '14 at 17:36

0 Answers0