Implementing a sidebar nav using android architecture components

245 Views Asked by At

With the new architecture components of android you can't use the default auto generated class navigation drawer class provided by android... why? because it extends from AppCompatActivity to provide the use of support.v7 lib for widgets like toolbar etc. When using now the new architectures component Lifecycleactivity instead of extending AppCompatActivity you can't implement the default navigation drawer class - can anyone give me a workaround or an example how to do this?

1

There are 1 best solutions below

0
On BEST ANSWER

From the Lifecycle documentation:

Note: Since the Architecture Components are in alpha stage, Fragment and AppCompatActivity classes cannot implement it (because we cannot add a dependency from a stable component to an unstable API). Until Lifecycle is stable, LifecycleActivity and LifecycleFragment classes are provided for convenience. After the Lifecycles project is released, support library fragments and activities will implement the LifecycleOwner interface; LifecycleActivity and LifecycleFragment will be deprecated at that time.

They go on to provide instructions for implementing a LifecycleOwner, which allows you avoid using LifecycleActivity:

public class MyActivity extends AppCompatActivity
    implements LifecycleRegistryOwner {
  LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);

  @Override
  public LifecycleRegistry getLifecycle() {
    return lifecycleRegistry;
  }
}