Question

I need to extend ActionBarImpl, which is part of com.android.internal.app. But it is not recomended to do so, since it is bound to change anytime in new android releases.
Since I do not intend to re-implement ActionBarImpl I thought I will "cheat" by creating a class in this way:

public class MyActionBar extends ActionBar {
    private ActionBar ab;

    public MyActionBar(Activity activity) {
        ab = activity.getActionBar();
    }

    @Override
    public void setCustomView(View view) {
        ab.setCustomView(view);

    }

    ... (so on with all ActionBar abstract methods)

In words: I extend ActionBar + have a private member where I get the actual activity´s ActionBar and delegate all method calls to it.

Is there any drawback in doing it this way? I am not breaking compatibility,am I?

Was it helpful?

Solution

What you are going to do is to apply Decorator pattern. But it seems not to work as you want, because your activity will still use the original instance of the ActionBar, not the decorated one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top