android mapview slow and unresponsive - android

In my app mapview works great on some phones and very poorly on other phones. it seems to be a RAM issue, ie. phones with a lot of ram and a lot of heap work great and smoothly, phones without work very poorly.
I am recycling bitmaps and clearing things, but it doesn't seem to help. During app development it seemed kind of random when some phones would have issues with the mapview, but now it seems very consistent.
Basically on phones that don't work well, the mapview tiles load slowly, other parts of the app function very slowly, and the google map search does not give search suggestions or update the map with the address searched for.
On phones that do work, mapview tiles load quickly, other parts of the app function very quickly, the google map search gives search suggestions and the map updates exactly as desired.
what causes this and how would I improve it? (it is standard mapview code)
I saw a similar question about "android mapview is slow", basically was my problem, but the solution was irrelevant for me, how do apps that use mapview account for this?

Have you looked at this bug report (and related workarounds):
http://code.google.com/p/android/issues/detail?id=2181

Well you don't actually supply any code, but have you considered that the problem might be related to something else than the mapview? Or have you considered that perhaps you could improve the performance in other ways? There isn't much you can do with the mapview itself to improve performance.
You could investigate if the mapview slow without overlays. I recently found out my implementation of itemizedoverlay was bad because I was adding items and calling populate every time I added a new item instead of calling populate when I was done adding items. This didn't give any problems before (without tab layout) but with the tabs it worked really slow.
Another thing you could try was to go away from tabs with activities (I assume you do this now) and use tabs with fragments instead. And yes this is possible with mapview just dl one of the many fragmentmapactivities or make your own fragmentmapactivity.

One thing that will defiantly improve your performance will be setting the mapView as the top view of your activity.
MapView myMap = createMapView();
setContentView(myMap);
And I will even suggest you to do this within a new activity. Of course if you can.

Related

Google Map View is leaking very much

I've previously used the MapFragment, but it was slow for my needs. The MapView is almost instantly and fits my needs exactly. But there is one thing they both have in common:
Huge memory leaking.
I've 'destroyed' the MapView like I should when exiting the activity and it still leaks. The MapView is in an activity that is frequently opened and closed and opened quickly again. Could that be the issue?
Here are some screeenshots of my hprof files (I'd rather not upload the hprof files, due to possible sensitive information):
I've had multiple leaks, and they al point to the same classes.
However, I am using a custom class, which is unneeded at this moment, and I'll revert back to the default MapView.
I am not sure if that's the case, but I did something stupid using Kotlin.
Kotlin got null-safety.
googleMapView?.onDestroy()
I called that in onDestroy() of my Fragment. Guess what? googleMapView was null, that's why it didn't call it's onDestroy()! Wasted around 2 hours on this, because I thought some of my custom classes kept references or other things that led to this...

WebView slow scrolling

For some reason the WebView I am using is quite slow, I don't have to much of a problem with the loading times for web pages, although if there is a way to improve that I would appreciate it. But my main concern is the jagged laggy scrolling. I'm reasonably sure there must be a way to get it working more smoothly, as other apps using (I assume) the WebView don't have this problem. I suppose it may be possible that these other apps are using some private web client although it seems to me very unlikely that all of them would. Others have asked similar questions on SO, but none of the answers are particularly effective.
i think you have this code in your manifests
android:hardwareAccelerated="false"
android:largeHeap="true"
you have to delete if you have it.
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
This work for me.
It's really hard to guess what your problem might be given the amount of information you have provided:
Did you declare that you want software rendering in your application's manifest (or by
setting the WebView's layer type)? Maybe try hardware mode.
What is the page that you're trying to load? Maybe there's tons of CSS/JavaScript going on there? Does a simpler page scroll well?
Which version of Android are you seeing this on, have you tried others? Maybe this is specific to a device?
Is the scroll not smooth (are you not hitting 60fps) or is there a large lag between the finger moving an the page moving? If it's the latter - maybe you have touch handlers slowing things down.
The above is just stuff from the top of my head. There are great articles out there on the topic, such as this one. Also, if you're using the Chromium WebView you can use the profiling tools via remote debugging

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.

How do you change the look-and-feel of MapView display on Android?

This may not be possible, but I would like to change how maps look in the Android app I'm working on. I've gotten the basic functionality working via the MapView class, but I can't find any information on how I might change how the maps are rendered. For instance, I might want the background to be black instead of the normal tan. Any ideas?! Hack answers are fine at this point if there aren't any standard ways to do this.
You could try putting a transparent overlay item with a tinge.
The MapView has a couple of modes like Satellite terrain
Try using OpenStreetMap for Android for a different look

Categories

Resources