On 06/05/14 19:20, 'Tor Norbye' via adt-dev wrote:
> On Tue, May 6, 2014 at 1:48 AM, Roman Mazur <
mazur...@gmail.com
> <mailto:
mazur...@gmail.com>> wrote:
>
> Currently 'ValidFragment' check produces an error if default
> fragment constructor in implicit.
> To be honest, I'm not satisfied with such a behaviour because it
> makes me add an empty constructor explicitly to a bunch of classes...
>
>
> That's a bug. I discovered it myself yesterday and fixed it:
>
https://android-review.googlesource.com/#/c/93424/
I don't think that was a bug.
AFAIK, Android explicitly requires an empty *public* constructor for
Fragments. I believe Java implicit constructors have default visibility.
From the Javadoc:
"Every fragment must have an empty constructor, so it can be
instantiated when restoring its activity's state." (though here it
doesn't actually say "public")
http://developer.android.com/reference/android/app/Fragment.html#Fragment()
The Android Studio "blank activity with fragment" creates a Fragment
with empty public constructor, and various code samples on the Android
site show explicit public constructors, e.g.:
http://android-developers.blogspot.de/2012/05/using-dialogfragments.html
If you don't provide a public constructor, at some point when the system
attempts to re-instantiate your fragment after restarting your process
from the background, you'll likely run into this ClassNotFoundException:
https://github.com/android/platform_frameworks_base/blob/android-4.4.2_r2/core/java/android/app/Fragment.java#L596-599
Regards,
Chris