Lately I was using support package android like actionbar activity or fragment activity to build an app. I combined many tutorial that don't use support package to my project, so the project can do thing that I need, but sadly, I had to overcome many errors, and that why this question fly in my head ...
I try to learn how the support package works, the articles pretty much said that support package works the same as the main package(is that we call it? sorry, I don't know), the difference is the support package works for android prior to honeycomb ...
And lastly is that okay to use both support package and main package together like using actionbar activity and fragment....
Thanks
There are some features that were added on later versions of Android such as ActionBar (post-Honeycomb) or RecycleView (post-Lollipop).
Using the support packages, we can use these features even on devices running earlier versions of Android.
They don't harm your code in any way.
Related
I have a question regarding the Android Support Libraries, Fragments, and as a specific example, the ViewPager class. My intention is to create an app with similar functionality to the sample provided on the Android Developer website (http://developer.android.com/training/animation/screen-slide.html or http://developer.android.com/training/implementing-navigation/lateral.html). Looking into their code, I've noticed they utilize the android.support.v4.app library, which from my research is the only way to access the ViewPager class.
In my situation, I have no interest in backward compatibility. The minimum API level is 14 (Ice Cream Sandwich) and the build target is 4.2 Jelly Bean. In it's simplest form, my app performs exactly as does the second demo I linked on the Android dev website - just swiping between three tabs with content in each.
All of the articles/posts/answers I've read seem to heavily favor the v4 support library. Now for my, albeit long-winded, question(s):
What's the best way to structure my application - using android.support.v4.app, and thereby using SupportFragments, or to use the Fragments provided in android.app - and why?
If Fragments from android.app are the way to go, what is the optimal way to approach ViewPagers?
If SupportFragments are best-suited to the task, I would estimate that they possess the same functionality as the other - so what's the purpose of having them at all inside android.app?
Hopefully someone with a clearer understanding can give me a bit of clarification because I'm boggled...
You can use ViewPager with native fragments from the android.app package with the adapters from the android.support.v13.app package. You have to use the v13 support jar for that.
There are two versions of the adapters that work with ViewPager, the ones in the v4 package are meant to be used with support fragments, the ones in v13 with native fragments.
The reason why there are now two fragment implementations is historical: Fragments in the android.app package were introduced with Android 3 for tablets only and the support library was created to bring fragments to phones running older versions. On Android 4 you have both.
From my own experience I would recommend using support fragments, even when developing for Android 4. Here are some reasons: Fragment or Support Fragment?
android.app.Fragment class is deprecated since Android P (link), so only android.support.v4.app.Fragment should be used everywhere.
If you're going to target API 11+, you won't need the support library [and your actual apk will be smaller, at least).
If you want to support anything before Android 3.x, you'll need the support library.
Is this what you're asking?
this is my sittuation ...
A customer gave me an application done partially by somebody else. That person used fragments to build the UI.
The guy who gave me the application to finish the development of it, just realized that he wanted that the application run on android devices with 2.X
So, I am wondering if it is possible to have two UI's : One for Android devices that support fragments, and another one for android devices which do not support fragments.
In case that is possible, can that be deffined on the xml as alternate resources is done ? Or that needs to be programatically? (I mean check android os version and alternate UI's)
Thanks!
Lucky for you, the Support Library has Fragments in it, and supports back to Android 1.6. So you can use the "support" class for Fragments and it will work on old and new devices alike.
http://developer.android.com/tools/extras/support-library.html
http://developer.android.com/training/basics/fragments/support-lib.html
"The type TabActivity is deprecated"?
I am making the Tabs of app following tutorial book.
I've checked from the android developer.com website, but i have no ideas on the significance of the following message : This class is deprecated.
New applications should use Fragments instead of this class; to continue to run on older devices, you can use the v4 support library which provides a version of the Fragment API that is compatible down to DONUT."* (http://developer.android.com/reference/android/app/TabActivity.html)
What is v4 support library?
How to finish the tab functions?
You can still use a deprecated package. It is however recommended to use Fragments, and thus the support package. You can read more about it here. However, if you are a beginner at java and android development, I would recommend ignoring the deprecation for now and come back to this when you have completed the tutorial you are currently using if you find it educating.
If you want to watch a nice example of tabbed navigation using Fragments, then create a new project in Eclipse using android 4.0 or later. Make sure your android-plugin is updated. You will get the option to create a project with basic navigation already implemented.
"Deprecated" means that the api developers don't recommend using it anymore, probably because its not a good model, or inefficient, etc. Fragments were introduced in Honeycomb and can be used to provide a similar functionality as tabs and is more in-line with android's current design philosophy.
Since Fragment was introduced in Android 3.0 Honeycomb, you might think you cannot use that for pre-Honeycomb devices. Enter Support Libraries. They are libraries which you can include in your application which needs to run on pre-Honeycomb and still use this class.
So if you want to, you can finish the TabActivity as described in whatever tutorial you are following, it'll probably work on a few more upcoming android versions. But it is recommended that you start using Fragments.
I am starting my programming with fragments. i want to do it for android 2.2 first then for android 3.0/3.1/3.2.
I added Compatibility package , all things i did.
What i want just give me some sample example for android 2.2 fragments for better understanding that how to use fragments in application.
there are the Api4+ and the API 13+ demos. You can download an install on your phone and try it and choose which one is the best for you. The source code is very helpful and commented.
I've had a problem with this and have been running my head up against it and couldn't see how to use an ActionBar in the app when running on v11/3.0+ and then use an in house ActionBar in v7/2.1
The problem is that when you use any of the tags (such as android:actionBarStyle) or libraries from v11 library, your app will no longer compile with a library lower than v11. Therefore you won't be able to run it on a phone.
However
I've been looking at the source to the Google IO 2011 application and it uses v7 as a default library. It is designed however to use the ActionBar as it has the above tag in it (android:actionBarStyle). But since I have a built version on my phone and it has alot of code for creating a fake ActionBar when on devices lower than v11 it obviously should be able to be built on both.
Obviously there is a peice of the puzzle I'm missing. How do I get the Google IO 2011 app building? What mechanism is in place which allows you to develop for multiple versions at once?
Someone please help.
Stupid Question which comes from confusing myself over 3 different issues I'm juggling.
Apps built with v11 library will happily run on a phone as long as the android:minSdkVersion attribute in the AndroidManifest.xml file has been set to or below the version of the phone. However, the functionality which relies on the later libraries won't work.
The reason I thought the Google IO 2011 app came with a default v7 library is that I created a project from the source in eclipse - I didn't import a project.
(And I'll write it here since I can - The Fragment code written into v11 code for convenience can't be used if you intent to use Fragments pre v11 as android.app.Fragment isn't compatible with android.support.v4.app.Fragment. It just needs to be ignored and hooks retrieved from getSupportManager() etc.).
So, I withdraw my question :)