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?
Asked
Active
Viewed 4,329 times
6
-
What did you mean by "is it worse than using AppCompatActivity" ? – Ojonugwa Jude Ochalifu Jan 06 '20 at 12:40
1 Answers
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.

Ani
- 1,041
- 6
- 15