The Navigator interface

Just as with Scenes, you can implement the Navigator interface to create your own Navigator. This time however, this is actually discouraged: it can be tricky to properly deal with managing the different lifecycles. There are a couple of excellent base classes available however that provide most of the basic implementations you'll need. If you still need to implement your own Navigator, have a look at Scene Management.

The Navigator interface describes the basic functionality for a Navigator. It provides several lifecycle describing methods, and allows interested parties to register themselves to be notified of Scene changes.

 1 interface Navigator {
 2 
 3     fun onStart()
 4     fun onStop()
 5     fun onDestroy()
 6     
 7     fun isDestroyed(): Boolean
 8     
 9     fun addNavigatorEventsListener(listener: Navigator.Events): DisposableHandle
10 
11     interface Events {
12 
13         fun scene(scene: Scene<out Container>, data: TransitionData? = null)
14         fun finished()
15     }
16 }

The first three methods describe the Navigator's lifecycle:

  • onStart(): Called when the Navigator is started;
  • onStop(): Called when the Navigator is stopped;
  • onDestroy(): Called when the Navigator gets destroyed;

As a user of one of the base classes mentioned above you usually won't have to override these methods, although you can hook into them when you need it.

The Navigator.Events interface can be implemented to get notifications of Scene changes.