1

I've used this answer: Same Navigation Drawer in different Activities to implement a navigation drawer that is shown in all activities.

I am not sure if this is the right way to go, but at the moment I have a main application, that contains some activities and implements the NavigationDrawer in the BaseActivity.

I would like to start by creating many android library projects that will have activities/fragments in them and their own logic. So for now, besides the main application, I've created one android library project and I can successfully start one of its' activities from the main application (from the NavigationDrawer).

The problem is that I cannot make it extend the BaseActivity and therefore the NavigationDrawer is not shown.

So, at the moment in the main application, I have:

activity_main.xml // it is the launcher activity
activity_one.xml
activity_two.xml
MainActivity.java
OneActivity.java
TwoActivity.java

That works fine. Now I want to add the library project into play, in which I have:

activity_three.xml
ThreeActivity.java

And now the problem is that in the library project, I cannot extend from the BaseActivity like that:

public class ThreeActivity extends BaseActivity{ // <-- There's an error here: Cannot resolve symbol 'BaseActivity'

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_three);
    }
}

Does anybody have any suggestions how to do that?

Should I just create another library project that has the BaseActivity and the navigation drawer ?

Community
  • 1
  • 1
Apostrofix
  • 2,140
  • 8
  • 44
  • 71

1 Answers1

2

Should I just create another library project that has the BaseActivity and the navigation drawer ?

Either that, or get rid of all the libraries and move everything into the one project. A library cannot inherit from classes from a project that consumes the library. A library can inherit from classes from a project that the library itself depends upon, though.

So, the app/ module could depend upon the three/ library (that has ThreeActivity), which in turn depends upon the base/ library (that has BaseActivity).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the quick answer! Just to make sure I understand - I should create a library project that has the `BaseActivity`. Then every other library could extend it. And then I can make one main project that also extends the `BaseActivity` project. I need to have them as libraries, because it will be easier to manage/maintain/develop in future. – Apostrofix Dec 20 '15 at 21:04
  • 1
    @Apostrofix: "Then every other library could extend it" -- libraries don't extend other libraries. Libraries can depend upon other libraries. "And then I can make one main project that also extends the BaseActivity project" -- you would need the app project to depend upon all of the other libraries, directly (e.g., the one with `ThreeActivity`) or indirectly (e.g., the one with `BaseActivity`). – CommonsWare Dec 20 '15 at 21:06