How to get LifecycleOwner in LifecycleObserver?

Observer methods can receive zero or one argument. If used(means you can go with zero argument too but IFF arguments are used), the first argument must be of type LifecycleOwner. Methods annotated with Lifecycle.Event.ON_ANY can receive the second argument, which must be of type Lifecycle.Event.

class TestObserver implements LifecycleObserver {
         @OnLifecycleEvent(ON_CREATE)
         void onCreated(LifecycleOwner source) {
               //one argument possible
              }
         @OnLifecycleEvent(ON_START)
         void onCreated() {
              //no argument possible
             }
         @OnLifecycleEvent(ON_ANY)
         void onAny(LifecycleOwner source, Event event) {
             //two argument possible only for ON_ANY event
             }
}

You shouldn't need to implement your own LifecycleRegistry - just use the one available from AppCompatActivity

public class MainActivity extends AppCompatActivity {
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);

      if (savedInstanceState == null) {
          getSupportFragmentManager().beginTransaction()
                  .replace(R.id.container, MainFragment.newInstance())
                  .commitNow();
      }

      getLifecycle().addObserver(new MyLifecycleObserver());
  }
}

If you separate the startFirebase call and the viewmodel observer you can observe the changes from the viewmodel directly in the fragment, i.e.

MyLifecycleObserver starts the firebase call when ON_START is emitted.

public class MyLifecycleObserver implements LifecycleObserver {
    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onStartListener(){
        FirebaseMassage.startFirebase();
    }
}

MainFragment observes the ViewModel directly.

public class MainFragment extends Fragment {

  @Override
  public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
      super.onViewCreated(view, savedInstanceState);
      massageViewModel.getMassage().observe(this, textMassage -> {
          FirebaseMassage.updateFirebaseMassage(textMassage);
      });
  }

You can just use another signature to get the LifecycleOwner like:

public class MyLifecycleObserver implements LifecycleObserver {


    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onStartListener(LifecycleOwner owner){
        ... 
    }
}