MapViews in Fragments API <11. - android

I have been researching this for a while now. I actually have 2 working applications that implement a map in a fragment. Each application uses a different approach. Wondering which is better if any. I am also wondering if i am just behind on this and maybe there is a better way that i have not found yet.
The 2 approaches.
One uses LocalActivityManager which is depreciated.
The other approach is detailed here using a Exchanger to coordinate between Activity and Map
The first method has the drawback of already being depreciated.
I thought i saw a problem with the second method but i am unable to find it again.
Is there any benefit to one method or the other. Or is there something else that i should be looking into?
Thankyou.

Look at this library (android-support-v4-googlemaps)
A port of the Android Compatibility package which makes FragmentActivity extend MapActivity. This is a hack to make it possible to use a MapView in a Fragment.
Moreover i use it instead of Compatibility package to build ActionBarSherlock - so i have map + fragments + action bar.

Related

Embed an activity in a tabbed UI from external applications

I want to make an application which embeds an activity in a tabbed UI from a number of applications. As far as I know it's officially disabled due to the security matter but probably some hacks exist!
I have heard of two ways:
converting the activity to a type of Fragment
using LocalActivityManager class which is currently deprecated.
I already tried both of them and failed due to lack of my ability. If there is something I missed or another approach, let me know!
Note that I can modify those because I have a source code of them.
I want to make an application which embeds an activity in a tabbed UI from a number of applications.
That is not possible.
As far as I know it's officially disabled due to the security matter but probably some hacks exist!
I doubt it.
I have heard of two ways
Neither of them are related to your problem as originally stated.
Note that I can modify those because I have a source code of them.
Then combine them into one application, creating one APK file. At that point, then you can start exploring converting UIs into fragments or otherwise combining things into a tabbed UI.

Why Group Activity is Deprecated

I am Searching for the answer of my questions
Why Group Activity is deprecated?
I did not find any proper answer. My second question is
Why we have to use Fragment instead of Group Activity?
I need answer of these question in detail.
You can get your detailed answer by reading The Android 3.0 Fragments API blog. One of the relevant point is:
Embedded Activities via ActivityGroup were a nice idea, but have always been difficult to deal with since Activity is designed to be an independent self-contained component instead of closely interacting with other activities. The Fragment API is a much better solution for this, and should be considered as a replacement for embedded activities.
You can also look at Is it advised to build all apps using fragments? question. Hope it helped.

Multiple maps v2 in TabActivity

I'm currently trying to have 2 maps v2 in different tabs of a TabActivity using MapView objects. The problem arises in the following scenario:
tab1 with a map is displayed
go to tab2 in order to display another map
in this second tab looks like the map image from first tab is overlapping the new map. See the following picture:
On the right you can see how the first map is still displayed on top of it. The touch events are going to the new map but that doesn't really help. I spent a lot of time trying to convert our app to use fragments and run into other types of issues. One of them being http://code.google.com/p/android/issues/detail?id=40035 so that's not a good option either.
So far I haven't been able to find any workaround. To easily try various changes I wrote a simple application and made it available here: https://github.com/cristizmf/TestMapsV2. It needs only the right location for maps library project and a good maps key in manifest.
Any ideas would be greatly appreciated.
Later edit: I've logged an issue for this: https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027&thanks=5027&ts=1362071369
We are having the exact same problem. I suspect this is caused by the fact that the new maps uses OpenGL - possibly android cant deal with having two OpenGL widgets in the view hierarchy at the same time even though one is hidden.
The only way we worked around this was to actually remove the mapview when leaving a tab, then construct a new one and add it back in when going back into the tab. This ensures that there are never two maps constructed at once.
Nasty, but it worked.
I ran into the same issue a few days ago and was pulling my hair out over what to do.
Originally I had my app set up with "Tabs the Fragment way" as seen here to avoid the deprecated TabActivity, and used this hack to allow me to incorporate Maps v1 in with the Fragments. It basically just masks an Activity as a Fragment.
But then switched to TabActivity further down the track for simplicity / it was better suited for the whole app.
But now obviously this 2x Maps v2 fragment problem has become an issue..
So I have reverted back to "Tabs with Fragments" and just have the "hack setup" as mentioned above for each tab, which allows to have an Activity for each tab, AND having more than one Maps v2 displaying for each Tab. I haven't gone into too much depth with it, but it seems to be doing the job atm, with having just thrown some code together to test it out..
Don't know if you're still having an issue with this / this obviously isn't the most correct solution, but just thought I'd share my two cents incase you still needed it.
Cheers.

Performance of multiple MapFragments (Android Map API v2)

I searched the docs of the new Google Android Map API v2, but didn't find anything about it. Before v2 we (officially) couldn't properly display more than one map per application (process). I assume that with MapFragment implementation it's no longer an issue. I also know, that Fragments can be self-contained since API 17. And, last but not least, there is compatibility package, which makes it possible to port it all back to at least API 8 (in API 7, there's no OpenGL 2.0 so the maps wouldn't work afaik).
Sa I have all the ingredients to port my app to Maps API v2 and implement the following scenario: ViewPager contains Fragments and each of them contains a MapFragment.
But should I do it? I mean, would I face performance issues if I had e.g. 20 Fragments containing MapFragments in a ViewPager?
If you found anything that addresses my concern in the docs or somewhere else, please tell me.
EDIT: Example usage: Let's imagine a screen containing informations about some specific item - place, event, article. Also let's imagine that, among other informations, it must contain a map to be fully functional. But I would like the user to be able to swipe to another item if he wants. Each item has its own map.
Side note: I know that I can implement one map outside the ViewPager and just update it based on the currently displayed item, but it's not what I'm looking for - it's not user-centered design.
Possible solution (but not checked yet). ViewPager only keeps a few (default - 3) Fragments in it's cache and recreates them when they're about to show up, so there won't be much memory overhead as only a few MapFragments are needed. The performance problem may be the MapFragment inflation which is quite heavy, I believe - but that can be solved with recycling of MapFragments.
So why won't I implement it if I believe it will work nice? There's another problem which makes it impossible to move MapFragments without the app look like it's broken. See this.
You could easily test it but my guess is that it would very much depend on the phone as Maps still is fairly heavy to run.
That said I'd never recommend this kind of user navigation. A map can already be swiped at so why would you add ViewPager swipe as well? This would make a very confusing user experience. If you want to switch between different views/point of interests you should add buttons (overflow menu buttons preferred as in the navigation app) or something similar that helps the user navigate around.
Yes, you definitely would run into performance issues because ViewPager doesn't employ view recycling by default; you can even bloat it with ImageViews let alone MapFragments.
As far as caching and recreating fragments in ViewPager - there's a HorizontalListView lib that'd probably save you the effort as it does support view recycling.

Android extend multiple activity types

I'm wanting to extend both a MapActivity and a FragmentActivity. I know Java doesn't allow multiple inheritance, so how do I do this? I've read something about a 'composite' type, but I've never implemented one so I don't know how to go about doing that.
Someone else HAS to have run into this before, how did you solve it?
EDIT: The reason I want this is because I have 3 activities in tabs; a map, an image gallery, and a settings list view. The code for all three of these "acitivities" is inside one big MapActivity called "Main". Yes I know this is ugly, and not good programming practice, and I don't remember why I wrote it this way. I think it was because I was reading most people recommended NOT having separate activities for separate tabs... which if I decided to split them into separate activities, I wouldn't have this problem anymore.
I have no idea why you would want such a thing, but I suppose the easiest solution is something like ActivityGroup, something similar to how TabbedActivity works.
I ended up solving this by going in and modifying the source of the Android support package and deploying my app with that. Outlined here, all I did was make FragmentActivity (android.support.v4.app) extend MapActivity. I don't think the reverse works... though maybe, and it would require you having the source of the mapping library you're using (in the case of Google Maps - no go)

Categories

Resources