I have an Android app that I would like to convert to an Android library. The app is based around one activity whose entire XML layout contains only a webview that covers the entire screen. The library UI (really, just the webview) must now be integrated into the layout of other apps. For example, one parent app has a tab structure. I would like to have the library webview displayed in one of the tabs, with the tabs always visible at the bottom of the screen. Ordinarily, I'd opt to set the app-library boundary at the activity level but that does not work in this case -- we cannot pop up a new Activity from the library because that would cover all of the screen and the tabs at the bottom.
What is the best way to convert this to a library so that it works within the tab structure of the parent app? Where should the app-library boundary be? Some of my ideas are:
Let the library user create an activity with the custom layout that he prefers (tabs in this case). Make sure that the layout contains a webview. Use findViewById to get the webview object and pass this object into the library for the library to use to display pages. Main disadvantage here is that parts of the library need to hook up some Broadcast receivers onto the parent activity (which is not really part of the library in this scenario), and this coupling seems rather dubious.
Perhaps use fragments which were introduced in Android 3.0. However, these mostly seem geared towards tablets. Would these work in this case?
Is there another option compatible with Android 2.1+ that I am not aware of?
I decided to go with Fragments, using the compatibility library.
http://developer.android.com/guide/topics/fundamentals/fragments.html
http://developer.android.com/sdk/compatibility-library.html
Fragments are really the best choice in this case because:
They have a life cycle similar to that of activities, making conversion easy.
They are a chunk of UI with related functionality, which is exactly what's needed in this case.
Related
I have an Android app with two classes:
-MainActivity
-SecondActivity
I have also two layouts for these classes (they are pretty similar).
I want to switch between these activities by 'shifting' to the right or to the left.
All materials I find are about switching by button.
Anyone would recommend using Fragments and ViewPager instead of Activity since you want sliding action and make use of the Android TabLayout.
Here is a tutorial that you can draw a basic idea from.
I have an existing app that is using a Dashboard style pattern where there's a main menu, and clicking icons on the main menu drive start different activities... In order to navigate to a different function, you need to go back to the Dashboard menu and select another icon.
I want to change my application to a tabbed format similar to the one below with Icons:
What type of View is being used below? Is this a FragmentActivity? Also, what is the best approach to go about conversion? I have a bunch of layouts with listviews in linear/relative layouts... Will I be able to reuse any existing code? I want also to be able to use the solution with Android 2.1 and up if possible.
Thanks!
In the image you provided, it looks to be a TabHost that is used (which can be within a normal Activity or a Fragment Activity) and will be available for Android 2.1 and beyond when using the Android Support library. Based upon your description, you most likely have an Activity per each of your items that you will probably want to convert into a different Fragment. This may take a little time, but a Fragment is very similar to a normal activity in many ways, so once you start getting used to it, converting over the old Activities should be a breeze.
If you plan on using these tabs and you follow the Android design UI guidelines, you may want to use the TabHost in conjunction with a ViewPager. There is a great tutorial for this online that also allows for backward compatibility (down to at least 2.1) found here: http://thepseudocoder.wordpress.com/2011/10/13/android-tabs-viewpager-swipe-able-tabs-ftw/
Support library for fragments/viewpager: http://developer.android.com/tools/extras/support-library.html
More info about a TabHost and using Tabs with fragments can be found here:
http://developer.android.com/reference/android/widget/TabHost.html
http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/
You can use TabLayout and a TabActivity to achieve layout in picture. Bad news is these are deprecated as of Android 3.0. Google advises to use fragments instead of these.
I'm developing an application and I want to place two activities in a tabbed layout. I need the ability for the first activity to send an intent and programmatically switch to the second tabbed activity. This seems possible and is outlined in other posts:
Launching activities within a tab in Android
However, this approach doesn't seem advisable and it makes use of ActivityGroup, which is now deprecated. Can anyone recommend a stable solution that would meet my design needs?
You may want to take a look at ViewPager from the support library, coupled with https://github.com/JakeWharton/Android-ViewPagerIndicator/blob/master/library/src/com/viewpagerindicator/TabPageIndicator.java
It will produce a tab-like interface that you can swipe through. You can explicitly change which tab is being shown by calling viewPager.setCurrentItem(int).
I am doing an application similar to Viber or Linphone, a SIP application basically. I have a main tabhost at the bottom of the screen. And inside each tab I set different activities(for example the historic). I have done this using ActivityGroup. Is that the right approach? As I have seen that ActivityGroup is deprecated, but I dont want to use fragments(most of phones dont support API 11). I have seen the ViewPager component, could be also an alternative? I guess I can change the event onFlip with my finger for the onClick on a specific botton. Am I doing it right using Activitygroup, or should I change to another component?
Usually the kind of thing you are describing can be done using a simple TabActivity.
I'm not sure why you decided to use ActivityGroup, but regarding your hesitation related to fragments - you can use the Compatibility library, which will give you fragment support for older platforms, albeit with some limitations.
I want to show my activities inside of a running activity. I need something like frame in html language that is used for showing other pages inside a page. I know Tabhost has this ability. Which one of other controls has this ability?
Thanks,
Google introduced fragments in Android 3.0 and upper to create a portion of user interface in an Activity. But it is not two Activity, becuase activity <> window. For lower version you can manually load xml layout in your activity.
The Fragment API is really your best choice, it's quite easy to use and you can dynamicly add them to your Activity Layout (take a look to Framgent For All - google Article) by code using the FragmentManager, this feature it's since 3.0 altough Google also released a pretty nice Compatibility Package that you can download out of the SDK Manager and added to your project like this Fragment For All: