1
+ package com .example .preferences ;
2
+
3
+ import android .app .Activity ;
4
+ import android .content .Intent ;
5
+ import android .content .SharedPreferences ;
6
+ import android .os .Bundle ;
7
+ import android .preference .PreferenceManager ;
8
+ import android .view .View ;
9
+ import android .widget .Toast ;
10
+
11
+ public class Main extends Activity {
12
+ private SharedPreferences sharedPreferences ;
13
+
14
+ /** Called when the activity is first created. */
15
+ @ Override
16
+ public void onCreate (Bundle savedInstanceState ) {
17
+ super .onCreate (savedInstanceState );
18
+ setContentView (R .layout .main );
19
+ sharedPreferences = PreferenceManager .getDefaultSharedPreferences (this );
20
+ }
21
+
22
+ @ Override
23
+ protected void onResume () {
24
+ super .onResume ();
25
+ String message = String .format (
26
+ "Prefs: List %s, Name %s, Choice %b" ,
27
+ sharedPreferences .getString ("listChoice" , "None" ),
28
+ sharedPreferences .getString ("nameChoice" , "No name" ),
29
+ sharedPreferences .getBoolean ("booleanChoice" , false ));
30
+ Toast .makeText (this , message , Toast .LENGTH_LONG ).show ();
31
+ }
32
+
33
+ public void showPrefs (View v ) {
34
+ Intent intent = new Intent (Main .this , DemoPreferenceActivity .class );
35
+ startActivity (intent );
36
+ }
37
+ }
0 commit comments