I found some threads that explain why a Fragment
class should be static
(not non-static inner) like this. But can't understand the reason for this error message:
This fragment class should be public (...)
I use Android Studio 3.1.2 and this is a part of my codes:
public class MainActivity extends android.support.v7.app.AppCompatActivity {
// ...
}
class DefaultFragment extends android.support.v4.app.Fragment {
// ...
}
The fragment is supposed to be used only in MainActivity
.
EDIT: There is some other information in IDE message. But are about constructors:
From the Fragment documentation:
Every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setArguments(Bundle) and later retrieved by the Fragment with getArguments().