Fix NPE initialising MyPreferencesFragment.
This commit is contained in:
parent
5bd2911754
commit
324b68717f
1 changed files with 8 additions and 6 deletions
|
@ -47,7 +47,9 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
myPreferenceFragment = new MyPreferenceFragment();
|
myPreferenceFragment = new MyPreferenceFragment();
|
||||||
myPreferenceFragment.setCaller(getIntent());
|
Bundle args = new Bundle();
|
||||||
|
args.putInt("id", getIntent().getIntExtra("id", -1));
|
||||||
|
myPreferenceFragment.setArguments(args);
|
||||||
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
@ -106,10 +108,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MyPreferenceFragment extends PreferenceFragment {
|
public static class MyPreferenceFragment extends PreferenceFragment {
|
||||||
Intent caller;
|
private Integer id;
|
||||||
|
|
||||||
public void setCaller(Intent i) {
|
@Override
|
||||||
caller = i;
|
public void setArguments(Bundle args) {
|
||||||
|
super.setArguments(args);
|
||||||
|
id = args.getInt("key");
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPreferencesFromResourceIfEnabled(PluginBase p, int type) {
|
void addPreferencesFromResourceIfEnabled(PluginBase p, int type) {
|
||||||
|
@ -121,8 +125,6 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Integer id = caller.getIntExtra("id", -1);
|
|
||||||
|
|
||||||
if (id != -1) {
|
if (id != -1) {
|
||||||
addPreferencesFromResource(id);
|
addPreferencesFromResource(id);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue