This repository was archived by the owner on Feb 26, 2023. It is now read-only.
RuntimeException with @PreferenceScreen #1392
Copy link
Copy link
Closed
Labels
Description
Hi,
I've tried to implement the preference screen in my app today and stumbled upon this bug (or am I doing something wrong?)
I have created a xml file with preferences, and annotated the activity :
@PreferenceScreen(R.xml.preferences)
@EActivity
public class SettingsActivity extends PreferenceActivity {
}and it gives me the error:
Caused by: java.lang.RuntimeException: This should be called after super.onCreate.
at android.preference.PreferenceActivity.requirePreferenceManager(PreferenceActivity.java:1439)
at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1511)
at package.name.SettingsActivity_.init_(SettingsActivity_.java:38)
at package.name.SettingsActivity_.onCreate(SettingsActivity_.java:32)
at android.app.Activity.performCreate(Activity.java:5990)
I guess the problem is in the generated class:
@Override
public void onCreate(Bundle savedInstanceState) {
OnViewChangedNotifier previousNotifier = OnViewChangedNotifier.replaceNotifier(onViewChangedNotifier_);
init_(savedInstanceState); // that line should be after onCreate (line 32)
super.onCreate(savedInstanceState);
OnViewChangedNotifier.replaceNotifier(previousNotifier);
}
private void init_(Bundle savedInstanceState) {
addPreferencesFromResource(xml.preferences); // line 38
}Is there anyone who can confirm the bug or indicate my mistake (I did everything as in the wiki section, so I think all should be fine)
Cheers!
Reactions are currently unavailable
Activity
dodgex commentedon May 4, 2015
For me with a PreferenceFragment instead of PreferenceActivity it works.
@WonderCsabo any ideas?
WonderCsabo commentedon May 4, 2015
This is a bug unfortunately. Actually we have a running test for this which passes, but it seems Robolectric have a different implementation than real Android code...
This should be fixed. Nonetheless i also encourage the usage of
PreferenceFragment, because this way is deprecated (and alsoPreferenceFragmentare working now with AA 😄 ).Noiseapps commentedon May 4, 2015
Ok, thanks for the quick response :-)
anyways, since there is no PreferenceFragment in the support library, how can I use it in the ActionBarActivity?
WonderCsabo commentedon May 4, 2015
I do not know why, but the Android folks still not provide a backport of
PreferenceFragmentin the support library. The good news is that there is an unofficial version if it. Bad news is: we do not support theandroid.support.v4.preference.PreferenceFragmentclass... But i think we should (which also adds a forward support of the official one if Google releases it). Please open a new issue for that.WonderCsabo commentedon May 4, 2015
@yDelouis @dodgex there are three issues raised about our new preference API today. Fixing these is easy fortunately. Should we create a hotfix release? Maybe it makes sense, because the next big release will be 4.0 with breaking changes.
dodgex commentedon May 4, 2015
I think we should fix those. I think it is not a good idea to keep them longer than necessary.
yDelouis commentedon May 5, 2015
Yes, we should create a fix release (3.3.1).
WonderCsabo commentedon May 5, 2015
I opened #1396 for the problem described in #1392 (comment).
WonderCsabo commentedon May 5, 2015
I opened PRs for these three problems. @yDelouis @dodgex @athkalia @Noiseapps can you test them?
@yDelouis after you review these we can release a hotfix.
WonderCsabo commentedon May 5, 2015
@yDelouis according to this, we should not merge these fixes into
develop, but to a hotfix branch which comes from master. Makes sense of course.dodgex commentedon May 5, 2015
@Noiseapps when minSdk is 11+ you can use the default PreferenceFragment even with
ActionBarActivityor the newAppCompatActivityWonderCsabo commentedon May 5, 2015
@dodgex bad idea. 😢 It will break the backstack and possibly other things (at runtime).
yDelouis commentedon May 5, 2015
@WonderCsabo, you're right, theses PRs should be merge in a hotfix branch.
WonderCsabo commentedon May 5, 2015
Side-note: I opened a ticket in the Android bug tracking system for the problem i just mentioned @dodgex.
WonderCsabo commentedon May 9, 2015
Fixed.