File: FragmentNotInstantiable.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (16 lines) | stat: -rw-r--r-- 856 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Every subclass of `Fragment` must be public and have a public, nullary
constructor. The Android framework will reflectively instantiate them after a
configuration change, such as screen rotation, and if the class is not
instantiable by `Class#newInstance()`, an `InstantiationException` will be
thrown.

In addition, it is strongly recommended that subclasses not have other
constructors with parameters, since these constructors will not be called when
the fragment is re-instantiated; instead, arguments should be supplied with
`setArguments(Bundle)` and retrieved with `getArguments()`.

For more information, please see the documentation for
[Fragment](http://developer.android.com/reference/android/app/Fragment.html#Fragment\(\)).

This check is an adaptation of the `ValidFragment` rule of
[Android Lint](http://tools.android.com/tips/lint-checks).