removing a mapView on android - crash

Hello,

When exiting a scene i want to remove the mapObject that has been created, so the native map isn’t visible in other scenes. The code i am using is:

function mapScene:exitScene( event )  
 nativeMap.parent:remove(nativeMap)  
 nativeMap = nil  
end  
mapScene:addEventListener("exitScene")  

On an iPhone or iPad this code works perfectly, and the map is removed. On an Android device however this makes my app to crash, I test it on a Samsung Galaxy Tab. Any suggestions of what I might be doing wrong or how i can remove a Map correctly on an Android device?

Thanks,
Philippe [import]uid: 213791 topic_id: 35266 reply_id: 335266[/import]

I just tested this on my Android device and it doesn’t crash for me.

I tried this…
[lua]nativeMap.parent:remove(nativeMap)
nativeMap = nil[/lua]

And I also tried this…
[lua]nativeMap.removeSelf()
nativeMap = nil[/lua]

Both of the above successfully destroyed the MapView without any error.

I’m thinking that you may be making functions calls to your [lua]nativeMap[/lua] variable after you have removed and nilled it out. Have a look at the Android log via Android SDK tool “adb logcat” or “ddms”. The log should provide clues as to why your app is crashing.
[import]uid: 32256 topic_id: 35266 reply_id: 140296[/import]

I just tested this on my Android device and it doesn’t crash for me.

I tried this…
[lua]nativeMap.parent:remove(nativeMap)
nativeMap = nil[/lua]

And I also tried this…
[lua]nativeMap.removeSelf()
nativeMap = nil[/lua]

Both of the above successfully destroyed the MapView without any error.

I’m thinking that you may be making functions calls to your [lua]nativeMap[/lua] variable after you have removed and nilled it out. Have a look at the Android log via Android SDK tool “adb logcat” or “ddms”. The log should provide clues as to why your app is crashing.
[import]uid: 32256 topic_id: 35266 reply_id: 140296[/import]

It appears with build 2373… If I do a mapView.parent:remove (or mapView:removeSelf), and nil out my mapView var… then later suspend the app, the GPS is stuck on (draining the battery quickly).

However, if I just nil the variable out and set the map.isVisible = false, I eventually get “blinky” maps when I re-enter the map screens (more blinky more times I enter, with degrading performance as well). I’d guess the sdk still considers the map “referenced” and doesn’t delete it (referenced by the main stage display group, since it wasn’t explicitly removed).

I saw some changes in the build notes that could be related to how native display objects are handled/removed, so maybe something changed regarding the mapView removal code… In any case, it appears the gps is not getting unhooked if you do a mapView:remove call…

OK, I just tested with the mapView sample app, and with a tiny modification, it does the same error / leaves the GPS on during app suspend…

By replacing the mapView sample apps button1Release() function with code to only remove the mapView, the error manifests

[lua]

local button1Release = function( event )
    – This finds the location of the submitted string.
    – Valid strings include addresses, intersections, and landmarks like “Golden Gate Bridge”, “Eiffel Tower” or “Buckingham Palace”.
    – The result is returned in a “mapLocation” event, handled above).
    if myMap then
        myMap:removeSelf()  – CoronaLabs endorsed technique to remove mapViews (or .parent:remove, same effect)
        myMap = nil
        local newLabel = display.newText( “***Map removed***”, 20, 70, shadow.contentWidth - 10, 0, native.systemFont, 14 )        
        newLabel.anchorX = 0.0        – TopLeft anchor
        newLabel.anchorY = 0.0        – TopLeft anchor
    end
end

[/lua]

This produces the same bug (leaves the GPS on during suspend).  The original mapView sample code correctly shuts off the GPS when the app is suspended.  But once you remove the mapView using the technique above, then suspend the app, the GPS remains on and drains the battery pretty quickly. There’s no way to turn it off at that point, short of terminating the app.

I’ve tried a good 6 hours worth of variations – not removing but only nil’ing the mapView, .parent:remove, etc, etc, and can’t find a workaround that doesn’t cause blinky maps or leave the GPS on during suspend.

Above was filed as case #34342.  I just tested again with build 2393, and the gps still remains on during app suspend when maps have been created / removed.  Is there any way for users to check bug status yet?

Unfortunately there isn’t a way to look into the bug tracker for users.  The bug got submitted during our public release cycle and I don’t know that Engineering has mapped out the things they are going to fix next now that this release is complete and we resume daily builds.

Rob

It appears with build 2373… If I do a mapView.parent:remove (or mapView:removeSelf), and nil out my mapView var… then later suspend the app, the GPS is stuck on (draining the battery quickly).

However, if I just nil the variable out and set the map.isVisible = false, I eventually get “blinky” maps when I re-enter the map screens (more blinky more times I enter, with degrading performance as well). I’d guess the sdk still considers the map “referenced” and doesn’t delete it (referenced by the main stage display group, since it wasn’t explicitly removed).

I saw some changes in the build notes that could be related to how native display objects are handled/removed, so maybe something changed regarding the mapView removal code… In any case, it appears the gps is not getting unhooked if you do a mapView:remove call…

OK, I just tested with the mapView sample app, and with a tiny modification, it does the same error / leaves the GPS on during app suspend…

By replacing the mapView sample apps button1Release() function with code to only remove the mapView, the error manifests

[lua]

local button1Release = function( event )
    – This finds the location of the submitted string.
    – Valid strings include addresses, intersections, and landmarks like “Golden Gate Bridge”, “Eiffel Tower” or “Buckingham Palace”.
    – The result is returned in a “mapLocation” event, handled above).
    if myMap then
        myMap:removeSelf()  – CoronaLabs endorsed technique to remove mapViews (or .parent:remove, same effect)
        myMap = nil
        local newLabel = display.newText( “***Map removed***”, 20, 70, shadow.contentWidth - 10, 0, native.systemFont, 14 )        
        newLabel.anchorX = 0.0        – TopLeft anchor
        newLabel.anchorY = 0.0        – TopLeft anchor
    end
end

[/lua]

This produces the same bug (leaves the GPS on during suspend).  The original mapView sample code correctly shuts off the GPS when the app is suspended.  But once you remove the mapView using the technique above, then suspend the app, the GPS remains on and drains the battery pretty quickly. There’s no way to turn it off at that point, short of terminating the app.

I’ve tried a good 6 hours worth of variations – not removing but only nil’ing the mapView, .parent:remove, etc, etc, and can’t find a workaround that doesn’t cause blinky maps or leave the GPS on during suspend.

Above was filed as case #34342.  I just tested again with build 2393, and the gps still remains on during app suspend when maps have been created / removed.  Is there any way for users to check bug status yet?

Unfortunately there isn’t a way to look into the bug tracker for users.  The bug got submitted during our public release cycle and I don’t know that Engineering has mapped out the things they are going to fix next now that this release is complete and we resume daily builds.

Rob