• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.apis.preference;
18 
19 import com.example.android.apis.ApiDemosApplication;
20 import com.example.android.apis.R;
21 
22 import android.content.SharedPreferences;
23 import android.os.Bundle;
24 import android.preference.PreferenceActivity;
25 import android.preference.PreferenceManager;
26 
27 /**
28  * This activity is an example of a simple settings screen that has default
29  * values.
30  * <p>
31  * In order for the default values to be populated into the
32  * {@link SharedPreferences} (from the preferences XML file), the client must
33  * call
34  * {@link PreferenceManager#setDefaultValues(android.content.Context, int, boolean)}.
35  * <p>
36  * This should be called early, typically when the application is first created.
37  * This ensures any of the application's activities, services, etc. will have
38  * the default values present, even if the user has not wandered into the
39  * application's settings. For ApiDemos, this is {@link ApiDemosApplication},
40  * and you can find the call to
41  * {@link PreferenceManager#setDefaultValues(android.content.Context, int, boolean)}
42  * in its {@link ApiDemosApplication#onCreate() onCreate}.
43  */
44 public class DefaultValues extends PreferenceActivity {
45 
46     @Override
onCreate(Bundle savedInstanceState)47     protected void onCreate(Bundle savedInstanceState) {
48         super.onCreate(savedInstanceState);
49 
50         addPreferencesFromResource(R.xml.default_values);
51     }
52 
53 }
54