0

I'm getting confuse that when we are building our project in android studio we are asked to define from where we want to support till latest, what about if we don't include support library which says that it supports backward compatiblity? then only methods i get will be of latest version and the older versions will not able to run our code, am i right? also I'm unable to understand these lines from documentation

Note: FragmentActivity is a special activity provided in the Support Library to handle fragments on system versions older than API level 11. If the lowest system version you support is API level 11 or higher, then you can use a regular Activity

but If Im extending Activity instead of FragmentActivity in this case

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportFragmentManager().findFragmentById(R.id.frag_map);
}

getSupportFragmentManager is unresolved, although I'm building project that is for higher than API 11 then why they say you should use Activity? and if i use getSupportFragment is unresolved.

Later in documentation they say:

If you're using the v7 appcompat library, your activity should instead extend AppCompatActivity, which is a subclass of FragmentActivity. For more information, read Adding the App Bar).

does v7 does not support version older than API 11?

blackHawk
  • 6,047
  • 13
  • 57
  • 100
  • 1
    I don't get the question ... documentation is clear: use `FragmentActivity` if you wana support system older then API 11, if not, you may use regular `Activity` ... using `AppCompatActivity` will support lower API versions as it's extends `FragmentActivity` ... obviously there is no `getSupportFragmentManager` in regular `Activity` class but obviously it has same method without Support in the name... *does v7 does not support version older than API 11?* why you are thinking that? logic says: no, it obviously support api < 11(till 25, 26 doesn't support 11 and 13) – Selvin May 12 '17 at 09:54
  • what is when you say "doesn't support 11 and 13"? – blackHawk May 13 '17 at 15:11
  • It should be *between 4/7 and 13* ... [Google drops support of devices older than 14 in support library v26](https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0-alpha1) – Selvin May 15 '17 at 08:05

1 Answers1

1

UPDATE:

As per the changes in Compat libs support versioning with the release of 24.2.0 and greater, the minimum supported version has become the same for v4 and v7, i.e, API level 9. Here is what the docs say now:

Some of the Support Library packages have package names to indicate the minimum level of the API they support, using a v# notation, such as the support-v4 package. Starting with Support Library version 24.2.0 (released in August 2016), the minimum supported API level has changed to Android 2.3 (API level 9) for all support library packages. For this reason, when working with any recent release of the support library, you should not assume that the the v# package notation indicates a minimum API support level. This change in recent releases also means that library packages with the v4 and v7 are essentially equivalent in the minimum level of API they support. For example, the support-v4 and the support-v7 package both support a minimum API level of 9, for releases of the Support Library from 24.2.0 and higher.

The main difference then lies between the specific features introduced by each. Both have different feature sets. For ex, AppCompatActivity lies in v7 while FragmentActivity lies in v4. In this case, AppCompatActivity should be preferred but other features don't intersect largely.

Read here: https://developer.android.com/topic/libraries/support-library/index.html

Disclaimer: While choosing to support a minimum version, you must pick carefully for intersecting versions. It is therefore highly recommended to refer to docs as Android APIs update pretty fast and answers like these get obsolete.


ORIGINAL ANSWER:

You are confusing yourself. It's simple really. As per my understanding:

  • Support classes require support components, i.e, Activity, Fragments, etc. So, a support Fragment manager would require a FragmentActivity or an AppCompatActivity. So, not including a support library while using getSupportFragmentManager is bound to give compile time error.
  • Since Fragment was introduced at API level 11, that's why FragmentActivity would be used as a support component on API level < 11 so that you don't have to write code like, if(Build.VERSION_CODES < HONEYCOMB){} for standard and crucial Android features released in each Android release. But FragmentActivity is in v4 compat lib. If you don't aim to support that back, use the v7 one, AppCompatActivity
  • Your regular Activity is supposed to the the Activity from your targeted Android APIs(android:targetSdkVersion).

Also see, Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?

Community
  • 1
  • 1
Manish Kumar Sharma
  • 12,982
  • 9
  • 58
  • 105
  • Could you explain it: "Support classes require support components" – blackHawk May 12 '17 at 10:48
  • @blackHawk : The SupportFragmentManager stands true to its name i.e, it requires an Activity or Fragment from support library and not the latest targeted library because the support fragment manager and other components, all lie separately in the support library. – Manish Kumar Sharma May 12 '17 at 10:50
  • @blackHawk : And FragmentActivity and AppCompatActivity are both from support libraries v4 and v7 respectively. – Manish Kumar Sharma May 12 '17 at 10:51
  • could you please see this link, in all support library it says "This library is designed to be used with Android 2.3 (API level 9) " what does it mean, ain't there no distinction? – blackHawk May 13 '17 at 15:12
  • @blackHawk : Which link? – Manish Kumar Sharma May 13 '17 at 15:18
  • @blackHawk : Just think about it like, "There is a library out there I can add on top of everything I am using to have an additional feature set". This library is just like a 3rd additional dependency like normally you would add for example RecyclerView or a Firebase additionally. And, it happens to support Android 2.3 and higher. Btw, the only feature in this lib is RenderScript in case you decide to find a RenderScript, you may take a look at it. – Manish Kumar Sharma May 13 '17 at 15:26
  • what about API level 9, because I have in my mind to support recent feature back to api 11 i have to use v7 and if I want to support even older api level suppose api 9 I have to to v4, is that true? – blackHawk May 13 '17 at 15:55
  • @blackHawk : You can use either depending on the API level you need to support as minimum. And yes that's true what you have understood. – Manish Kumar Sharma May 13 '17 at 16:00
  • then in link provided, why they say same thing "There are several libraries designed to be used with Android 2.3 (API level 9) and higher." under v7 support library and v4 support library as well? it should be different for each support library – blackHawk May 13 '17 at 16:06
  • @blackHawk : Great catch. I updated myself with docs and turns out there have been changes. See the updated answer now. – Manish Kumar Sharma May 13 '17 at 16:42
  • Glad i have been reading this and thinking of posting screenshot of that, btw could you guide me about themes and styles with support library components or classes, what i understand is that if im using v7 i have to use same library's themes or style otherwise i can't go ahead, but where can i see to what component i can use what theme or style(what style it contain so i can override) – blackHawk May 13 '17 at 16:49
  • @blackHawk : Well, unfortunately no...I don't have much experience with themes and styles. I myself am learning a bit of everything. There is too much to learn if someone wants to be a Full Stack developer. But, I am sure there are resources like docs, Vogella, Google's official Android tutorial videos on Youtube, Udacity's Android course, TreeHouse's Android course. Good luck! – Manish Kumar Sharma May 13 '17 at 16:57