AppCompatActivity vs AppCompatDelegate
Asked Answered
N

1

6

Recently I discovered what is AppCompatDelegate so a natural question arises - is it worse than using AppCompatActivity or do they have their differences and what are they?

Normy answered 4/7, 2017 at 2:12 Comment(1)
What did you mean by "is it worse than using AppCompatActivity" ?Alluvium
C
9

If your activity class is not extending AppCompatActivity but you still want to use some of its features then you can you AppCompatDelegate.

You can create Appcompatdelegate with following lines of code in your activity class:

private AppCompatDelegate getDelegate() {
    if (mDelegate == null) {
       mDelegate = AppCompatDelegate.create(this, null);
    }
    return mDelegate;
}

Here is the example if you want to add Toolbar in your activity but your class is not extending AppCompatActivity.

https://medium.com/google-developer-experts/how-to-add-toolbar-to-an-activity-which-doesn-t-extend-appcompatactivity-a07c026717b3

Ciborium answered 4/7, 2017 at 3:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.