As Mordag said, as of now, both the LifecycleActivity and LifecycleFragment are not yet implemented. In their documentation Google says:
Any custom fragment or activity can be turned into a LifecycleOwner by implementing the built-in LifecycleRegistryOwner interface (instead of extending LifecycleFragment or LifecycleActivity).
However, that is only half the story, because naturally you are using these Lifecycle Aware components to be able to react to your Activity/Fragment lifecycles and with their code snippet it just doesn't work, because initialising a LifecycleRegistry with the Activity/Fragment like this
LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);
only gets you a Lifecycle in the INITIALIZED state.
So, long story short, in order for this to work right now (BEFORE their 1.0-release) it is you who have to implement the Lifecycle of the Activity/Fragment that implements the LifecycleRegistry. So, for each callback of the Activity/Fragment you need to do this:
public class ScoreMasterFragment extends Fragment
implements LifecycleRegistryOwner {
private LifecycleRegistry lifecycle;
@Override
public LifecycleRegistry getLifecycle() {
return lifecycle;
}
public ScoreMasterFragment(){
lifecycle = new LifecycleRegistry(this);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//more code here
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
}
@Override
public void onStart() {
super.onStart();
//more code here
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START);
}
@Override
public void onResume() {
super.onResume();
//more code here
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
}
@Override
public void onPause() {
super.onPause();
//more code here
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE);
}
@Override
public void onStop() {
super.onStop();
//more code here
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
}
@Override
public void onDestroy() {
super.onDestroy();
//more code here
_lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
}
This will likely be in the code of the future LifecycleActivity and LifecycleFragment, but until then, if you put your Activities/Fragments observing some LifecycleAware object (like LiveData) you will have to do this.
In the case of LiveData, because it will not notify its observers unless they are at least in the STARTED state and in other cases because other LifecycleAware components cannot react to a Lifecycle if its only state is INITIALIZED.