previous objects of google Maps v2 android are not being removed - android

As we seen in above diagram, This is related to fragments and Maps.
If we click on left side fragment, The corresponding details are shown in detailview and Map view Which are in tabhost (Right side Fragment). In the mapview we shown markers for particular data.
Problem : If we click on another item on left fragment, the right side fragment should be replaced with new details. I was able to do it.**But,the older objects of Map are still in memory.****
and some times showing, due to java.lang.ref.FinalizerRefernce
I examined with eclipse MAT. The screen shots are also attached below.
Every time when reloads, heap memory consumption is increasing..
And I followed the map lifecycle. During destroying of frament, I added the code like..
mapView.onDestroy() also.
Can anybody tell me where i was doing wrong?
Thanks Inadvance.

Related

Multiple MapViews in fragments bug, all maps visible

I am using a single activity with multiple frgmetns where each holds a MapView in its fragment.
This is a reported bug, that i occurs on 4.0.4 android (probably on 4.0 also) but works properly on higher versions.
https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027
Multiple maps v2 in TabActivity
When a new fragment is added both maps show. If a third fragment is added all tree maps are shown. I have tried applying the hideStupidMaps fix as discussed above but it provides no result( i have added calls to hide/show maps in onResume/onPause).
I have also added calls to hide the previous map before calling FragmentManager and its transaction but no result.
I have tried setting MapView visibility to INVISIBLE but also no result, the map previos map still shows, like no refresh is happening?
Is there a way to set zIndex to MapView? I know you can set z index when using MapFragment through GoogleOptions but i cant find an option to do that with MapView?
GoogleMapOptions options = new GoogleMapOptions();
options.zOrderOnTop(true);
fragmentMap = SupportMapFragment.newInstance(options);
I have managed to get it working. The problem was that i was actually calling hideStupidMaps after fragment transaction, and on 4.0.4 android it didnt have any effect while it worked on 4.1. I moved the call before the Fragment transaction and it worked. The only downfall is that for a moment the user can see the map disappear before Fragment animation starts.
I have also added a OnBackStackChangedListener where i would show the previously hidden map when returning via back button/action bar.
Hope it helps someone, and a piece of advise, avoid multiple maps in fragments if you can...

Android Fragments or Layouts - advice needed

I am developing an application which should display a number of tiles on the first page. Tiles are generated dynamically from json, each should allocate itself according to size specified in json and should take as much screen as required. Each tile represents short summary of information. The requirement is that when tile is pressed user is redirected to another page which provides more detailed info (like a form) which takes the whole page. User then should be able to go back to previous page and choose another tile if needed or go back to the first one. I don't know in advance how many tiles there will be and what are their components, so everything is dynamic. There is also a possibility that small tiles(with different info) can be required to be drawn on detailed view.
At the moment I am on the stage where all small tiles are displayed on the first page and I need to find the best way to display detailed view and allow user to navigate easily and quickly. Each tile extends RelativeLayout because of absolute positioning of components inside. I am considering switching tiles from Layout to Fragments because they seem to be providing flexibility required and many articles and tutorials I search refer to them. In this case when user presses the tile fragment, all existing tiles would be replaced with required detail fragment. Pressing back button would replace detail fragment with previous smaller ones on the screen (would it be display all of them or only one?).
Another option I am considering is to leave layouts and on tile press redirect user to a separate Activity with detail view. In this case navigating back seems to be destroying activity and it will need to be redrawn again if user wants to come back to it (redraw is not desirable).
My question is what is better for performance. Each tile as well as detail view might have some images in it and full page will take time to load. But figuring out how to handle this with Fragments programmatically might take a while and the last thing I want to find is that Fragments are not suitable. Maybe you have other ideas for scenario described? Any good tutorials/articles where Fragments are created and managed programmatically completely(no XML).
I am relatively new to Android and completely lost now.
Edit:
Thanks everyone for your advice. I can't choose the best answer at this point. I have to do some more research and learning now. Will do that later.
Fragment should be the best way to go. because filling details in a fragment dynamically is easy. will help check some codes i have written that could solve this
Fragments are a new style in Android for creating GUIs, they should not be compared with simple Activity + xml layout's in performance terms. Fragments were created to make it easier to build complicated GUIs, on both phones and tablets. You can create low performance GUI using both methods.
From your description I suppose its best to create two fragments, and wire them in Master Detail pattern. Master will be your json list with short summaries, and detail will be your additional data fragment. You can still put both fragments in separate activities, and show detail fragment from master one (master actitity will get hidden) - this makes sense on small screen devices. But you can show both fragments on one screen on tablets. See 'Master Detail Flow Template', http://developer.android.com/tools/projects/templates.html.
So fragments gives you a lot of flexibility to modify your UI, without huge code rewrites.
Some new widgets like ViewPager will work only with fragments, so if you want to use it you better invest time in learning them.
From what you have described above you do not need Fragments to do this. On your main page you can use a GridView to display your tiles. You could create two other Activities. One called TileActivity which will open each time a tile is pressed. Then you could create a PopulateActivity which would populate the TileActivity with the relevant information depending on which Tile was pressed. In terms of performance instead of closing the TileActivity to go back to the main page you could use Intent Flags so that the TileActivity isn't closed it is just added to the stack and then restarted instead of recreated each time its called.

What kind of "floating" Android view does Foursquare use for it's Activity Feed?

On the Foursquare activity screen, a map is displayed at the top of the scrollable activity feed, and the text appears to "float" above the map. When the map is tapped it expands to fill the screen. What kind of Android views are they using here?
I think it's a FrameLayout, with the map fragment below and a listview above, being the first element of the list an empty transparent rectangle. When you click that first element an animation is triggered to hide the listview and set the map's configuration.
I'm trying to achieve a similar screen. That's the general idea, not sure yet about the details, I'll add some code later if I can.
Can't be certain, but I'm 99% sure that they are using the Google Maps api, with markers added. Check out this link for more information: https://developers.google.com/maps/documentation/android/marker

Android: Bottom of Google Maps gets black inside the application

I have one Map on my main activity and It works fine. Recently I added another small map view on one of my sub activities using the same google map key. Now when I press back after looking at the map on sub activity, it returns to the main view and bottom of the map on main activity turns black. See the attached image.
Is there anyone who has faced this problem and know why sometimes bottom of map turns balck?
You can only have 1 map activity per process.
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapActivity.html

Problems when my googlemaps view activity regain the focus (map with black zone in down part of the window)

i have a problem with my app, it haves a lot of activitys, two of them haves googlemap views. My A activity haves a full mapview and my B activity haves a small map view. OK, when i am on the B activity and press back key somethimes until i return to my A activity, the map of my A activity shows with errors, with a black zone in the down part of the window. THis only happens when i press back from the B activity.
Because this, i need to implement/override onResume() method of A to RESTART THE ACTIVITY TO REPAINT ALL FROM SRATCH.... LIKE TO DO AGAIN ONCREATE METHOD, but i think i can't call it again... or i can?
wich code i have to put to repaint all the window from scratch ?
i tryed with all this:
-mapView.requestLayout() --> it works a little, repaints the map but with the zoom and showing the last map showed on B activity... no sense :S i dont want that. Are different maps, not have to show the same coordinates and zoom, each one have his own.
-mapView.invalidate() --> doesn't works
-mapView.postInvaldiate() --> doesn't works
Having multiple maps (MapViews) running in the same process is not adviced. Typically, using the default configuration, all Activities (including MapActivities) run within the same process.
According to the api docs, located here
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapActivity.html
Only one MapActivity is supported per process. Multiple MapActivities running simultaneously are likely to interfere in unexpected and undesired ways.
Issues I encountered with multiple MapViews within the same process :
Although it appears that there are 2
different maps in the app, changes in
the first map (ex: moving it to a
certain position, toggling sattelite
view) also got reflected in the
second map, as if it was the same
map.
On occasion, map tiles were not
getting loaded properly. Portions of
the map, or the complete map remained
empty.
In Logcat, apache http connection pool errors were logged (originating from the TilesProvider)
There is a defect logged here : http://code.google.com/p/android/issues/detail?id=3756
A solution / workaround is to host your maps in different processes :
<activity android:name=".MapView1" android:process=":MapView1">
<activity android:name=".MapView2" android:process=":MapView2">

Categories

Resources