Android battery issue? (GPS?)

Recently installed build 903 to get the android maps, built and tested. A few hours later, my phone started crying that there was only 5% battery left. Charged it, raan my app, and again, several hours later, my battery was dead - and I wasn’t even running the app most of the time!

Finally, after another charge, I ran my app, “suspended” it, and noticed something… The little android GPS icon was active at the top of the screen - while my app was suspended. My guess is the sdk left the gps on, and it was trying to send updates to my app - constantly eating the battery.

Didn’t get to test on iOS…

Joshua? Anyone have an idea if this is correct? [import]uid: 79933 topic_id: 30744 reply_id: 330744[/import]

*Slaps Forehead*
That would be a bug. Crap… I forgot to disable/enable the GPS when the app gets suspended/resumed. Nice find. I should have time to fix this in about a week and a half from now.

That said, the GPS will be correctly disabled when removing the map view object from the screen or when pressing the Back key to leave the app. We just need to do the same with the suspend event. So, I hope you don’t mind waiting until we fix it. In the meantime, feel free to play with Android maps some more and let us know if you catch anything else. We’ve actually put a lot of testing/debugging time into it already on various Android devices and OS versions… including testing the various errors that can occur (sudden loss of Internet access or user disabling the GPS) and we’ve written code to make it auto-recover. So, hopefully that gives you some confidence. [import]uid: 32256 topic_id: 30744 reply_id: 123163[/import]

Not just playing with them, my app is about ready to launch, and extensively uses maps… So, rest assured Joshua, if I notice anything else, you’ll hear from me :wink:

Overall though, the android mapViews look pretty solid, well done! [import]uid: 79933 topic_id: 30744 reply_id: 123165[/import]

I just wrote it up as a bug now. The bug number is 17225.

I’ve only heard of one other bug where some Android devices will show a white line along the right side of the map view, but I haven’t been able to reproduce it on my devices. Have you seen this? [import]uid: 32256 topic_id: 30744 reply_id: 123326[/import]

Nope, haven’t seen it (uhhhm, probably). The closest thing I’ve seen to something like that is only on my satellite view map. When it is refreshing, sometimes the leftmost column of map “tiles”, and topmost column of tiles doesn’t refresh for a minute, leaving a white strip across the top and/or left side of my maps for a few seconds (but they eventually refresh). You might see this when zooming out, or panning the mapview. The height/width of the strip (sometimes large, sometimes small) seems to vary based on the map zoom level / how google has carved up their satellite image data.

Perhaps on a slow cellular connection, the tiles timeout and are never sent, leaving a white strip? Or perhaps this is totally unrelated…

A couple questions might be:

  • Which mapview does it occur on, just satellite? Does switching to the other views eliminate it?
  • Does scrolling or zooming the map eliminate it, or cause it to occur?

Note1: All of my map “widths” are multiples of 4 (I’m old school like that). Perhaps there’s a clipping or buffer error for unusual widths?
Note2: I did notice some unwanted visual effects in my initial implementation of mapviews, when I tried re-using the same mapviews on different “screeens” by manipulating the mapviews size (width/height, xScale, yScale stuff). This ended up giving me stretched and scrunched looking maps, so I switched to using separate mapview objects for different screens. Lesson learned: Always create the mapview at the size it’s going to be displayed at, to avoid odd scaling effects.

Like I said, the mapviews look pretty solid to me (and I’m giving them a workout), not surprised you only heard of one other bug! [import]uid: 79933 topic_id: 30744 reply_id: 123329[/import]

Hmmm… if the map tiles are slow to load or refresh, I’m not sure if there is much I can do about that. Perhaps I can change the background color to help mask this issue. I did set up the map view to cache its content so that the last viewed mapped tiles will appear while the device is offline.

Also, it sounds like I need to play with resizing the map view some more. It’s not supposed to stretch its contents. It might be another Android hardware acceleration bug that I’ll have to work-around. I’ll check it out. Thanks! [import]uid: 32256 topic_id: 30744 reply_id: 123343[/import]

*Slaps Forehead*
That would be a bug. Crap… I forgot to disable/enable the GPS when the app gets suspended/resumed. Nice find. I should have time to fix this in about a week and a half from now.

That said, the GPS will be correctly disabled when removing the map view object from the screen or when pressing the Back key to leave the app. We just need to do the same with the suspend event. So, I hope you don’t mind waiting until we fix it. In the meantime, feel free to play with Android maps some more and let us know if you catch anything else. We’ve actually put a lot of testing/debugging time into it already on various Android devices and OS versions… including testing the various errors that can occur (sudden loss of Internet access or user disabling the GPS) and we’ve written code to make it auto-recover. So, hopefully that gives you some confidence. [import]uid: 32256 topic_id: 30744 reply_id: 123163[/import]

Not just playing with them, my app is about ready to launch, and extensively uses maps… So, rest assured Joshua, if I notice anything else, you’ll hear from me :wink:

Overall though, the android mapViews look pretty solid, well done! [import]uid: 79933 topic_id: 30744 reply_id: 123165[/import]

I just wrote it up as a bug now. The bug number is 17225.

I’ve only heard of one other bug where some Android devices will show a white line along the right side of the map view, but I haven’t been able to reproduce it on my devices. Have you seen this? [import]uid: 32256 topic_id: 30744 reply_id: 123326[/import]

Nope, haven’t seen it (uhhhm, probably). The closest thing I’ve seen to something like that is only on my satellite view map. When it is refreshing, sometimes the leftmost column of map “tiles”, and topmost column of tiles doesn’t refresh for a minute, leaving a white strip across the top and/or left side of my maps for a few seconds (but they eventually refresh). You might see this when zooming out, or panning the mapview. The height/width of the strip (sometimes large, sometimes small) seems to vary based on the map zoom level / how google has carved up their satellite image data.

Perhaps on a slow cellular connection, the tiles timeout and are never sent, leaving a white strip? Or perhaps this is totally unrelated…

A couple questions might be:

  • Which mapview does it occur on, just satellite? Does switching to the other views eliminate it?
  • Does scrolling or zooming the map eliminate it, or cause it to occur?

Note1: All of my map “widths” are multiples of 4 (I’m old school like that). Perhaps there’s a clipping or buffer error for unusual widths?
Note2: I did notice some unwanted visual effects in my initial implementation of mapviews, when I tried re-using the same mapviews on different “screeens” by manipulating the mapviews size (width/height, xScale, yScale stuff). This ended up giving me stretched and scrunched looking maps, so I switched to using separate mapview objects for different screens. Lesson learned: Always create the mapview at the size it’s going to be displayed at, to avoid odd scaling effects.

Like I said, the mapviews look pretty solid to me (and I’m giving them a workout), not surprised you only heard of one other bug! [import]uid: 79933 topic_id: 30744 reply_id: 123329[/import]

Hmmm… if the map tiles are slow to load or refresh, I’m not sure if there is much I can do about that. Perhaps I can change the background color to help mask this issue. I did set up the map view to cache its content so that the last viewed mapped tiles will appear while the device is offline.

Also, it sounds like I need to play with resizing the map view some more. It’s not supposed to stretch its contents. It might be another Android hardware acceleration bug that I’ll have to work-around. I’ll check it out. Thanks! [import]uid: 32256 topic_id: 30744 reply_id: 123343[/import]

Just to let you know, I did look into this issue, but it turns out that it is not an easy fix. Disabling the GPS on the map is easy enough but I’ve discovered that re-enabling it is very unreliable. It’s kind of crazy really. The function I’m calling on the Android side says it succeeded in enabling the GPS, but it’s a lie and it doesn’t actually turn it back on. :-/

So, I’m going to need a little more time in solving this issue. Sorry about the delay.

If you do not need location tracking, then I can offer you a work-around. If you remove the [lua]ACCESS_FINE_LOCATION[/lua] and [lua]ACCESS_COARSE_LOCATION[/lua] Android permissions then that will safely prevent the GPS from being enabled at all.

If you do need location tracking, then the only other work-around that I can think of is to destroy the MapView when the app is suspended and re-create it when it resumes. Although, I think that’s kind of a lame hack, but I’m not sure what else to offer at the moment. [import]uid: 32256 topic_id: 30744 reply_id: 125314[/import]

That sounds like both good and bad news… It’s great that your looking into it in detail, to do it “right”. Bad news of course that it’s going to take a little time.

I’ve got a few weeks to my app launch, and if your efforts aren’t completed by then, it looks like I will be trying to see if any of the following options would work out:

  • Remove runtime listener for location events - you said destroy the mapviews - I’ll probably try to just remove the location listener first, and re-initialize it on resume.
  • Centralize map code. I’ve got many maps (half a dozen?) that are created on various screens as the user accesses them. If removing the listener doesn’t cut it, I’ll try centralizing my map code (storing variables for active maps), and destroy/recreate them on suspend/resume…
  • Exit on suspend – Although I have a login, I might be able to cache the info and silently log them in… Unfortunately, they won’t resume where they left off… A bunch more work, and I might be able to fake it (take the app back to exactly where they left off).

But in any case – a HUGE thanks for the heads up Jason!!! It’s enabled us to create a fallback plan in case you can’t resolve it at the SDK end in time for our launch. [import]uid: 79933 topic_id: 30744 reply_id: 125432[/import]

Yeah, sorry about the delay. I’m just trying to do what I can to give you a reasonable solution until I can provide you a “real” fix.

I know for a fact that removing the location or mapAddress listener will not solve this problem. The GPS is enabled by default once the map view is shown, just like how it is done on iOS. Removing the map view is the only sure way of forcing the GPS off at the moment. The only with this of course is that you have no means of restoring the map view at the exact region it was set to before.

This week I’m scheduled to work on another feature on our roadmap. If all goes well, I should have time to “solve” this issue next week. I know exactly what I need to do now. I just need about a day to do it. I also plan on solving another Android map view bug mentioned in the link below. I’m sure that would interest you as well.
http://developer.coronalabs.com/forum/2012/04/02/maps#comment-125313
[import]uid: 32256 topic_id: 30744 reply_id: 125467[/import]

Just to let you know, I did look into this issue, but it turns out that it is not an easy fix. Disabling the GPS on the map is easy enough but I’ve discovered that re-enabling it is very unreliable. It’s kind of crazy really. The function I’m calling on the Android side says it succeeded in enabling the GPS, but it’s a lie and it doesn’t actually turn it back on. :-/

So, I’m going to need a little more time in solving this issue. Sorry about the delay.

If you do not need location tracking, then I can offer you a work-around. If you remove the [lua]ACCESS_FINE_LOCATION[/lua] and [lua]ACCESS_COARSE_LOCATION[/lua] Android permissions then that will safely prevent the GPS from being enabled at all.

If you do need location tracking, then the only other work-around that I can think of is to destroy the MapView when the app is suspended and re-create it when it resumes. Although, I think that’s kind of a lame hack, but I’m not sure what else to offer at the moment. [import]uid: 32256 topic_id: 30744 reply_id: 125314[/import]

That sounds like both good and bad news… It’s great that your looking into it in detail, to do it “right”. Bad news of course that it’s going to take a little time.

I’ve got a few weeks to my app launch, and if your efforts aren’t completed by then, it looks like I will be trying to see if any of the following options would work out:

  • Remove runtime listener for location events - you said destroy the mapviews - I’ll probably try to just remove the location listener first, and re-initialize it on resume.
  • Centralize map code. I’ve got many maps (half a dozen?) that are created on various screens as the user accesses them. If removing the listener doesn’t cut it, I’ll try centralizing my map code (storing variables for active maps), and destroy/recreate them on suspend/resume…
  • Exit on suspend – Although I have a login, I might be able to cache the info and silently log them in… Unfortunately, they won’t resume where they left off… A bunch more work, and I might be able to fake it (take the app back to exactly where they left off).

But in any case – a HUGE thanks for the heads up Jason!!! It’s enabled us to create a fallback plan in case you can’t resolve it at the SDK end in time for our launch. [import]uid: 79933 topic_id: 30744 reply_id: 125432[/import]

Yeah, sorry about the delay. I’m just trying to do what I can to give you a reasonable solution until I can provide you a “real” fix.

I know for a fact that removing the location or mapAddress listener will not solve this problem. The GPS is enabled by default once the map view is shown, just like how it is done on iOS. Removing the map view is the only sure way of forcing the GPS off at the moment. The only with this of course is that you have no means of restoring the map view at the exact region it was set to before.

This week I’m scheduled to work on another feature on our roadmap. If all goes well, I should have time to “solve” this issue next week. I know exactly what I need to do now. I just need about a day to do it. I also plan on solving another Android map view bug mentioned in the link below. I’m sure that would interest you as well.
http://developer.coronalabs.com/forum/2012/04/02/maps#comment-125313
[import]uid: 32256 topic_id: 30744 reply_id: 125467[/import]

Saw you did some map tweaks, like for nook. Still seeing the gps on after suspending. Could use this fix any day now :slight_smile:

God’s speed, Joshua Quick! [import]uid: 79933 topic_id: 30744 reply_id: 126549[/import]

Yeah, I haven’t taken care of the MapView GPS issue yet, but it’s still high on my todo list. Right now, Nook HD is top priority on the Android side of things… as I’m sure you can see on our forum threads and blog posts. We hope to be done with our Nook HD testing/debugging by this coming Monday. So far, it’s been moving along quite well. [import]uid: 32256 topic_id: 30744 reply_id: 126572[/import]

Saw you did some map tweaks, like for nook. Still seeing the gps on after suspending. Could use this fix any day now :slight_smile:

God’s speed, Joshua Quick! [import]uid: 79933 topic_id: 30744 reply_id: 126549[/import]