I'm working on an old Android project, did you know, what's the impact when I change ActionBarActivity (that's deprecated) by AppCompatActivity in all classes of the project ? Thank you.
1 Answers
Copied from sergej shafarenka's answer
ActionBarActivity
(the one extending AppCompatActivity
class) is a safe to use backward compatibility class. Its deprecation is just a hint for you asking to use new AppCompatActivity
directly instead. AppCompatActivity
is a new, more generic implementation which uses AppCompatDelegate
class internally.
If you start a new development, then you should rather use new AppCompatActivity
class right away. If you have a chance to update your app, then replace deprecated ActionBarActivity
by the new activity as well. Otherwise you can stay with deprecated activity and there will be no difference in behavior at all.
Regarding AppCompatDelegate
, it allows you to have new tinted widgets in an activity, which is neither AppCompatActivity
nor ActionBarActivity
.
For instance, you inherit an activity from an external library, which, in turn, does not inherit from AppCompatActivity
but you want this activity to have tinted materials widgets (views). To make it happen you need to create an instance of AppCompatDelegate
inside your activity, override methods of that activity like addContentView()
, setContentView()
etc. (see AppCompatDelegate
javadoc for the full list of methods), and inside those overridden methods forward the calls to inner AppCompatDelegate
instance. AppCompatDelegate
will do the rest and your "old-fashion" activity will be "materialized".
-
Thanks for reply, so if I understood correctly, if I make a copy of any occurrence of `ActionBarActivity` and replace with `AppCompatActivity` it will not affect my code? Or do I do nothing at all and just use `AppCompatActivity` in the new activities created? – Kheiro Ok Jan 23 '17 at 13:23
-
Even your first sentence is correct. Secondly you can use AppCompatActivity to your new activity. – W4R10CK Jan 23 '17 at 13:27