Search code examples
javaandroidandroid-studiointellij-ideaandroid-activity

Why does overriding onCreate(Bundle, PersistableBundle) not work?


Going through android development at the moment and by mistake I overrode onCreate(Bundle, PersistableBundle) instead of simply onCreate(Bundle) and so the activity wouldn't launch. I fixed it by using the correct overload, which was rather difficult to find but that's a different matter.

My question is this: Why didn't that work? Why does overriding onCreate(Bundle, PeristableBundle) not work, i.e. why isn't it called and why does overriding the other overload work?


Solution

  • onCreate(Bundle) is the usual method you will implement always.

    onCreate(Bundle, PersistableBundle) gets called only if you set the persistableMode, as documentation says:

    void onCreate (Bundle savedInstanceState, PersistableBundle persistentState)

    Same as onCreate(android.os.Bundle) but called for those activities created with the attribute persistableMode set to persistAcrossReboots.

    More about persistableMode: https://developer.android.com/reference/android/R.attr.html#persistableMode