I opened my old Android TV app project and tried to update the dependencies. I then updated the appcompat libraries to 27.1.1. I opened the leanback fragments and Android Studio warned me the BrowseFragment is deprecated and I should use BaseSupportFragment instead. Same case for other leanback fragments. I then changed all the fragment to AppCompat version (except for LeanbackSettingsFragment as there was no AppCompat version provided) and then changed my Activities extend AppCompatActivity.
After I made these changes, I built the app but when I launched the app I saw this error in logcat:
Unable to start activity ComponentInfo{net.swiftzer.trainboard.dev/net.swiftzer.trainboard.main.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
The theme I used for the app and activities are all under Theme.Leanback. But I checked the theme is based on platform native theme.
Should I stick with the deprecated leanback fragment classes or the leanback library do provides AppCompat themes? The leanback library is like a half-baked one. I saw the leanback library do provides an AppCompat version of fragments last year but no sample projects was using them. Now they marked the fragment classes extended from android.app.Fragment as deprecated but they didn't provide proper way to migrate.
You can't use Theme.Leanback for Activities extending AppCompatActivity. For using support fragments you can't extend the activity with android.app.Activity either. For using support fragments extend your activity with android.support.v4.app.FragmentActivity.
You are not allowed to use AppCompat theme for Android TV with Leanback library.
You should extend your BaseActivity of the FragmentActivity to benefit from the Support Components.
Related
Given the following:
Android documentation says :
AppCompatActivity - Adds an application activity class that can be used as a base class for activities that use the Support Library action bar implementation.
I'm not considering adding action bar to my activity
I need some material design widgets, which I can control only through AppCompat or material theme, but the latest need API >= 21, which is not my case.
I tested Theme.AppCompat.Light.NoActionBar with Activity class and it works well.
--
Is there an issue with using Activity class with AppCompat theme in my case?
The AppCompat library is intended to make compatibility with olders API, so the Theme and all components may work well in older systems.
I think the only concern is to always use the AppCompat elements and not the regular ones.
Example, use AppCompatEditText, AppCompatTextView, etc... And always refers to they with the AppCompat (AppCompatEditText editText;)
I have used a lot the support library and not have others issues, considering the visual elements may be a little different when using an API minor than 21
No.There is not issues with AppcompactActivity & support libaray. You can refere this link
To gain more rich & amazing look go with support library,Try to do material design
I am building app with the sdk levels (min 19- max 22), And i want to use material design in my app. Should i extend Activity or AppcompatActivity? What is the difference? I know AppcompatActivity is support library for backward compatability, Other than that is there any main difference between both?
Extending Activity is deprecated so you should use AppCompatActivity.
Ya we can.Just add the library in the Gradle file and use it in the activity.
I have an existing app with a minSdk of 14, now targeting 21, and I would like to use Theme.AppCompat to get the "Material look" throughout. This app also uses ActionBar tabs and ViewPager (FragmentPagerAdapter, etc.). I was previously using the native ActionBar and Fragment classes, but in order to use AppCompat from support.v7 it looks like I also have to use support.v7.app.ActionBar and related classes.
The issue I then ran into is that some support library ActionBar classes, such as the ActionBar.TabListener abstract interface, define methods that require the support library version of Fragments (support.v4.app.Fragment, et al). So now I'm faced with extensive modifications throughout the app to import the support library classes, change to getSupportFragmentManager, etc.
Is this the only route I can take for using the AppCompat themes for V14-21 -- switch entirely to the support library for both the action bar and fragments? Do some of these classes pass thru to the native classes at execution time?
Simple question.
Given AppCompat theme with new MaterialDesign in mind in pre-lollipop device.
Given Activity extending ActionBar activity as it is suggested by Google
Given REAL (PostHoneycomb) Fragment on the Activity
Results are
1. Activity has correctly picked up theme with nice accent colors wherever they are needed
Included fragment (throw dynamic transaction adding, not from XML) does not inherit Material Design theme from Activity and has old Honeycomb blue seekbar buttons
The same fragment layout design in AndroidStudio shows correct AppCompat theme
Eplicit theme enforcing on Fragment onCreateView using ContextWrapper doesn't work either.
p.s. Can't post screenshots as I don't have reputation
This was an issue with AppCompat 22.1.0 - update to a newer version (either 22.1.1 which contains the fix or 22.2.0 - the current latest version).
In Android what is the main difference between extending Lifecycler Activity, Activity,ActionBarActivity & AppCompactActivity? How do these classes differ from each other in terms of usage?
extending ActionBarActivity gives you the ActionBars functionality on every API level >= 7
by extending Activity you can avoid adding additional projects/libraries to your project but you'll lack the ActionBar on api levels below 11
edit: More details:
ActionBarActivity is part of the Support Library. Support libraries are used to deliver newer features on older platforms. For example the ActionBar was introduced in API 11 and is part of the Activity by default (depending on the theme actually). In contrast there is no ActionBar on the older platforms. So the support library adds a child class of Activity (ActionBarActivity) that provides the ActionBar's functionality and ui
edit2: Update April 2015 - it looks like the ActionBarActivityis deprecated in revision 22.1.0 of the Support Library. AppCompatActivity should be used instead.
edit3: Update Aug 2017 - LifecycleActivity is a LifecycleOwner but:
"Since the Architecture Components are in alpha stage, Fragment and
AppCompatActivity classes cannot implement it (because we cannot add a
dependency from a stable component to an unstable API). Until
Lifecycle is stable, LifecycleActivity and LifecycleFragment classes
are provided for convenience. After the Lifecycles project is
released, support library fragments and activities will implement the
LifecycleOwner interface; LifecycleActivity and LifecycleFragment will
be deprecated at that time."
(copied from the Architecture Components guideline)
If you look carefully, you will see this
public class ActionBarActivity extends FragmentActivity
implements ActionBarDrawerToggle.DelegateProvider TaskStackBuilder.SupportParentable
Here you can read about FragmentActivity:
http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
And differences between Activity and FragmentActivity:
Difference between Activity and FragmentActivity
Also, there are some new themes for styling actionBar...
https://developer.android.com/training/basics/actionbar/styling.html
Actionbar is introduced in API level 11. com.android.support:appcompat-v7:+ is a support library which allows you to have an ActionBar in your app for devices running on Android 3.0 or below. So, if you need actionbar below api level 11 your Activity needs to extend ActionBarActivity.
If you are targetting api level 11 and above then you don't need to extend ActionBarActivity and reference AppCompat. You can simply extend Activity and you will have actionabr by default.
Android Studio default project includes it automatically in dependencies and extends ActionbarActivity instead of Activity in order to use it.
The ActionBarActivity or the SupportActionBarActivity have additional methods and properties that are not in a generic Activity. for example methods for adding tabs are present in the ActionBarActivity and not in a generic Activity.
The major difference being you don't get an ActionBar on a generic Activity.
ActionBarActivity just has more support libraries and better usage of the newer themes available from api 11.
"In its most basic form, the action bar displays the title for the activity and the app icon on the left. Even in this simple form, the action bar is useful for all activities to inform users about where they are and to maintain a consistent identity for your app."
You are using Android support library When you come to to the Actionbaractivity . so the uses of Support library is your application can be suport for maximum number of devices. Support library gives to your application the power of Backward compatibilty. Actionbaractivity gives you the mulitiple feature like Actionbardrawer toggle etc.. there are more support libraries available. see this link .. and share to your friends...https://developer.android.com/tools/support-library/index.html