2

I tried to save string value after the app closed and re open.

I look at all of the SharedPreferences but i didn't understand if i need to open new activity or what.

So if you have any idea it will be very helpful.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
kipo
  • 63
  • 1
  • 1
  • 6
  • It seems you have a problem with your code. However, we can't help unless we have [code or information that can reproduce the problem](http://stackoverflow.com/help/mcve). Otherwise, we are just blindly guessing. – gunr2171 Aug 01 '14 at 14:13
  • 1
    I dont know how to add SharedPreferences to my code – kipo Aug 01 '14 at 14:14
  • Have you done an research on the topic yet? The implied question "how do I do that" is too broad. Take a look at the related questions list to the right. – gunr2171 Aug 01 '14 at 14:15
  • More info on Xamarin's `ISharedPreferences` here: [How do I use SharedPreferences in Xamarin.Android?](http://stackoverflow.com/a/26668566/383414) – Richard Le Mesurier Oct 31 '14 at 06:20

1 Answers1

4

what I recommend that you do is to implement shared preferences... going by this way

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor = preferences.edit();
editor.putstring("PreferenceName","YOUR PREFERENCE VALUE");
editor.commit;

and whenever you want to check the loginMethod value just call the preference value like this...

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String myValue= preferences.getString("PreferenceName", "");

if you need more assistant I'll be more than happy to help you

adinas
  • 4,150
  • 3
  • 37
  • 47
geekCode
  • 336
  • 2
  • 11
  • Where should I put the first part of the code? – kipo Aug 01 '14 at 14:52
  • where are you trying to implement the shared preferences?? – geekCode Aug 01 '14 at 14:56
  • https://www.dropbox.com/s/ms8vys7jexxrt4b/t1.PNG – kipo Aug 01 '14 at 15:03
  • I'm trying to get the value of t1.Text and when the app is closed and re open t1.Text will be in the same place and the same value – kipo Aug 01 '14 at 15:04
  • amm yes you can go by the shared preference way... what you can do is whenever your activity call the method onDestroy... you save the value of t1 in your preferences... then when the onCreate method is called you get the value that you have stored and display it... – geekCode Aug 01 '14 at 15:13
  • Im sorrey if I sound like an idiot but I dont know how to do that – kipo Aug 01 '14 at 15:15
  • mmm... the you will have to google it... I'm just giving you a guide to start with... it's just an idea!!... and your question was how to implement shared preferences! – geekCode Aug 01 '14 at 15:18
  • Thank you are very nice I will search it :) – kipo Aug 01 '14 at 15:19
  • I'm sorry I could not helped you... but if the answer gave some help the you can accepted...!! Cheers!! – geekCode Aug 01 '14 at 15:23