Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

RuntimeException with @PreferenceScreen #1392

Description

@Noiseapps

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!

Activity

  1. dodgex commented on May 4, 2015

    @dodgex
    Member

    For me with a PreferenceFragment instead of PreferenceActivity it works.

    @WonderCsabo any ideas?

  2. WonderCsabo commented on May 4, 2015

    @WonderCsabo
    Member

    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 also PreferenceFragment are working now with AA 😄 ).

  3. self-assigned this
    on May 4, 2015
  4. Noiseapps commented on May 4, 2015

    @Noiseapps
    Author

    Ok, thanks for the quick response :-)

    anyways, since there is no PreferenceFragment in the support library, how can I use it in the ActionBarActivity?

  5. WonderCsabo commented on May 4, 2015

    @WonderCsabo
    Member

    I do not know why, but the Android folks still not provide a backport of PreferenceFragment in the support library. The good news is that there is an unofficial version if it. Bad news is: we do not support the android.support.v4.preference.PreferenceFragment class... 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.

  6. WonderCsabo commented on May 4, 2015

    @WonderCsabo
    Member

    @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.

  7. dodgex commented on May 4, 2015

    @dodgex
    Member

    I think we should fix those. I think it is not a good idea to keep them longer than necessary.

  8. yDelouis commented on May 5, 2015

    @yDelouis
    Contributor

    Yes, we should create a fix release (3.3.1).

  9. WonderCsabo commented on May 5, 2015

    @WonderCsabo
    Member

    I opened #1396 for the problem described in #1392 (comment).

  10. WonderCsabo commented on May 5, 2015

    @WonderCsabo
    Member

    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.

  11. WonderCsabo commented on May 5, 2015

    @WonderCsabo
    Member

    @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.

  12. dodgex commented on May 5, 2015

    @dodgex
    Member

    @Noiseapps when minSdk is 11+ you can use the default PreferenceFragment even with ActionBarActivity or the new AppCompatActivity

  13. WonderCsabo commented on May 5, 2015

    @WonderCsabo
    Member

    @dodgex bad idea. 😢 It will break the backstack and possibly other things (at runtime).

  14. yDelouis commented on May 5, 2015

    @yDelouis
    Contributor

    @WonderCsabo, you're right, theses PRs should be merge in a hotfix branch.

  15. WonderCsabo commented on May 5, 2015

    @WonderCsabo
    Member

    Side-note: I opened a ticket in the Android bug tracking system for the problem i just mentioned @dodgex.

  16. WonderCsabo commented on May 9, 2015

    @WonderCsabo
    Member

    Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions