Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18244] Android: MapView crashes within Fragments

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-03-30T19:42:25.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.0.0, Release 4.1.0
ComponentsAndroid
LabelsTi.Map, mapView
ReporterManuel Lehner
AssigneeHieu Pham
Created2014-12-16T16:10:43.000+0000
Updated2015-05-07T13:37:23.000+0000

Description

The issue title may be a little general but I'm not able to be more specific because this happens whenever the parent view of the mapview is a Fragment. You can easily reproduce this bug with this test code:
Ti.UI.createAlertDialog({
    androidView: require('ti.map').createView()
}).show();
App crashes with this:
[ERROR] :  TiApplication (main) [712,712] Sending event: exception on thread: main msg:android.content.res.Resources$NotFoundException: Unable to find resource ID #0x3e8; Titanium 3.6.0,2014/12/11 14:51,7bde3b5
[ERROR] :  TiApplication android.content.res.Resources$NotFoundException: Unable to find resource ID #0x3e8
[ERROR] :  TiApplication 	at android.content.res.Resources.getResourceName(Resources.java:2026)
[ERROR] :  TiApplication 	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:939)
[ERROR] :  TiApplication 	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
[ERROR] :  TiApplication 	at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
[ERROR] :  TiApplication 	at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
[ERROR] :  TiApplication 	at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
[ERROR] :  TiApplication 	at android.os.Handler.handleCallback(Handler.java:739)
[ERROR] :  TiApplication 	at android.os.Handler.dispatchMessage(Handler.java:95)
[ERROR] :  TiApplication 	at android.os.Looper.loop(Looper.java:135)
[ERROR] :  TiApplication 	at android.app.ActivityThread.main(ActivityThread.java:5221)
[ERROR] :  TiApplication 	at java.lang.reflect.Method.invoke(Native Method)
[ERROR] :  TiApplication 	at java.lang.reflect.Method.invoke(Method.java:372)
[ERROR] :  TiApplication 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
[ERROR] :  TiApplication 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
This not just happening with AlertDialogs, I've seen this error since a while here: https://github.com/manumaticx/Ti.DrawerLayout/issues/4 I think the cause for this is somewhere in [TiUIFragment](https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/view/TiUIFragment.java) as the FragmentManager fails to resolve the containers resource id. I've tested this with several Titanium versions (3.3.0 to 3.6.0).

Comments

  1. Mark Mokryn 2015-02-04

    We will need to update the ti.map API so that we pass it the parent fragment (or its ID) somehow.
  2. John Dalsgaard 2015-02-18

    Any ideas for workarounds - or a timeframe for a fix?
  3. Ingo Muschenetz 2015-02-20

    [~jda] I've placed this into triage.
  4. Mark Mokryn 2015-02-20

    I would just like to comment that the solution should take into account that *any proxy* may possibly contain a fragment, thus the solution cannot be restricted just to tabs, etc. Must have a generic solution for this.
  5. Frank Apap 2015-03-03

    When using the map with this module - http://gitt.io/component/dk.napp.drawer - + Alloy I get a different error but it seems to be related to fragments as well: [ERROR] : TiApplication: (main) [1545,1545] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apsquared.navtest/org.appcelerator.titanium.TiActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState; Titanium 3.5.0,2015/01/12 15:33,0014f83 [ERROR] : TiApplication: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apsquared.navtest/org.appcelerator.titanium.TiActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState [ERROR] : TiApplication: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395) [ERROR] : TiApplication: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453) [ERROR] : TiApplication: at android.app.ActivityThread.access$900(ActivityThread.java:173) [ERROR] : TiApplication: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) [ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:102) [ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:136) [ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5579) [ERROR] : TiApplication: at java.lang.reflect.Method.invokeNative(Native Method) [ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Method.java:515) [ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) [ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) [ERROR] : TiApplication: at dalvik.system.NativeStart.main(Native Method) [ERROR] : TiApplication: Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState [ERROR] : TiApplication: at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1354) [ERROR] : TiApplication: at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1372) [ERROR] : TiApplication: at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595) [ERROR] : TiApplication: at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574) [ERROR] : TiApplication: at org.appcelerator.titanium.view.TiUIFragment.(TiUIFragment.java:49) [ERROR] : TiApplication: at ti.map.TiUIMapView.(TiUIMapView.java:59) [ERROR] : TiApplication: at ti.map.ViewProxy.createView(ViewProxy.java:68) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:483) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:469) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:507) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:491) [ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:469) [ERROR] : TiApplication: at dk.napp.drawer.Drawer.processProperties(Drawer.java:317) [ERROR] : TiApplication: at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:1185) [ERROR] : TiApplication: at dk.napp.drawer.DrawerProxy.windowCreated(DrawerProxy.java:145) [ERROR] : TiApplication: at org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:32) [ERROR] : TiApplication: at org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:442) [ERROR] : TiApplication: at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:524) [ERROR] : TiApplication: at org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:18) [ERROR] : TiApplication: at android.app.Activity.performCreate(Activity.java:5451) [ERROR] : TiApplication: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) [ERROR] : TiApplication: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359) [ERROR] : TiApplication: ... 11 more
  6. Hieu Pham 2015-03-20

    AlertDialog isn't using fragment, therefore adding a map to an dialog isn't a nested fragment problem. This is a different problem which we will address later. One way to provide nested fragments support for map is to create a standalone map fragment, which you can then add it to a fragment manager of your choice. This will require some changes in the TiDrawer module (I have an example PR). https://github.com/appcelerator-modules/ti.map/pull/85 - Map PR (Fix a couple crashes mentioned above) https://github.com/appcelerator/titanium_mobile/pull/6733 - SDK PR (Introduce 'fragmentOnly' property for map module, when enabled would only build standalone map fragment) https://github.com/manumaticx/Ti.DrawerLayout/pull/19 - TiDrawer module PR (Example PR demonstrating how to use 'fragmentOnly' property)
  7. Hieu Pham 2015-03-20

    Test case:
       var TiDrawerLayout = require('com.tripvi.drawerlayout');
       var Map = require ("ti.map");
       
       var win = Ti.UI.createWindow({
           backgroundColor: 'white'
       });
       
       var drawer = TiDrawerLayout.createDrawer();
       
       var menu = Ti.UI.createTableView({
           data: [
               {title:"Home"},
               {title:"About"}
           ]
       });
       
       var cv = Ti.UI.createView({
       		backgroundColor: 'orange',
       	});
       	
       menu.addEventListener("click", function(ev) {
       	var rowData = ev.rowData;
       	if (rowData.title == "Home") {
       		drawer.centerView = cv;
       	} else if (rowData.title == "About") {
       		drawer.centerView = mapview;
       	}
       	
       });
       var mapview = Map.createView();
       drawer.setLeftView( menu );
       win.add(drawer);
       win.open();
       
    Testing steps: 1. Build TiDrawer module with the changes in the PR in previous comment 2. Use the pre-built map zip from the map PR in previous comment 3. Build SDK from PR in previous comment 4. Run the test case, swipe left -> right to open menu, click on 'About' to open a map 5. Click 'Home' to open a new view. Toggle back and forth to make sure everything works.
  8. Manuel Lehner 2015-03-20

    Hi , first of all, thanks a lot for your efforts. I'm stuck with this issue in so long and was really happy to see a progress here. I have build the SDK and ti.map- and drawer modules with your changes and have run the above test case. But unfortunately it does not work for me. I am getting the following error now:
       [ERROR] :  TiApplication: (main) [40601,40601] Sending event: exception on thread: main msg:java.lang.IllegalStateException: Can't change container ID of fragment SupportMapFragment{16065ed1 id=0x3e8}: was 1000 now 2131296337; Titanium 4.1.0,2015/03/20 13:21,3c79460
       [ERROR] :  TiApplication: java.lang.IllegalStateException: Can't change container ID of fragment SupportMapFragment{16065ed1 id=0x3e8}: was 1000 now 2131296337
       [ERROR] :  TiApplication: 	at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:429)
       [ERROR] :  TiApplication: 	at android.support.v4.app.BackStackRecord.replace(BackStackRecord.java:451)
       [ERROR] :  TiApplication: 	at android.support.v4.app.BackStackRecord.replace(BackStackRecord.java:443)
       [ERROR] :  TiApplication: 	at com.tripvi.drawerlayout.Drawer.replaceCenterView(Drawer.java:443)
       [ERROR] :  TiApplication: 	at com.tripvi.drawerlayout.Drawer.propertyChanged(Drawer.java:602)
       [ERROR] :  TiApplication: 	at org.appcelerator.kroll.KrollPropertyChange.fireEvent(KrollPropertyChange.java:21)
       [ERROR] :  TiApplication: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1083)
       [ERROR] :  TiApplication: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:347)
       [ERROR] :  TiApplication: 	at com.tripvi.drawerlayout.DrawerProxy.handleMessage(DrawerProxy.java:70)
       [ERROR] :  TiApplication: 	at android.os.Handler.dispatchMessage(Handler.java:98)
       [ERROR] :  TiApplication: 	at android.os.Looper.loop(Looper.java:135)
       [ERROR] :  TiApplication: 	at android.app.ActivityThread.main(ActivityThread.java:5221)
       [ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Native Method)
       [ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Method.java:372)
       [ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
       [ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
       
    where Drawer.java:443 is [this line](https://github.com/manumaticx/Ti.DrawerLayout/blob/502feff41e870af8fdafb896c3f2ac2bde445acd/src/com/tripvi/drawerlayout/Drawer.java#L442) Tested on genymotion emulator (4.3) and Nexus 5 device (5.0.1) I've also noticed that this solution would make it impossible to use a mapView together with other views (in a Ti.UI.View centerView container) - you could only use it as a standalone view, directly applied as centerView, right? Would it be possible to check if the view *or any of its children* is a mapView and handle the inner fragment in spite of that?
  9. Hieu Pham 2015-03-20

    Hi Manuel, That error indicates that 'fragmenOnly' was somehow switched off - i.e we added it to our container and give it id of 1000. It looks like for some reason this line isn't hit https://github.com/manumaticx/Ti.DrawerLayout/blob/502feff41e870af8fdafb896c3f2ac2bde445acd/src/com/tripvi/drawerlayout/Drawer.java#L434. Have you try creating the map view like this?
       var mapview  = Map.createView({fragmentOnly: true});
       
    This solution would work with other titanium views. It simply give you an option when creating the map view. If you want to add it to a fragment manager, you need the standalone fragment, otherwise it will generate the fragment with a container as default (which is the previous behavior before these PRs). Right now only map view uses TiUIFragment, so that's how you would check if a view is a map view, or you can do (getAPIName() == "Ti.Map") on the proxy (see my comments in TiDrawer PR). For instance, centerView uses fragment manager, so you would pick the standalone fragment when creating the view in your module. And if some other UI requires the non-standalone map fragment, you can create another map view like that. This approach gives you that flexibility. Edit: I'm on vacation next week, so if you have any more questions regarding this approach, please feel free to drop a comment and Ashraf can assist you. Thanks.
  10. Manuel Lehner 2015-03-25

    Sorry - it was my bad (I somehow checked out the wrong branch of the ti.map module). I've successfully tested your fixes, it works just fine :) Thank you !!!
  11. Manojkumar Murugesan 2015-03-25

    Great guys! Nice to hear. I have been looking for this fix almost for last one year. By any chance is it possible to move this fix into 4.0 release?
  12. Ashraf Abu 2015-03-26

    [~hpham] --Some minor changes required in the Ti.Map PR.- -Otherwise everything is all good.- Just the manifest requires change to 4.0.0 as I'm adding your changes backport to the 4_0_X branch.
  13. Ashraf Abu 2015-03-27

    PR for 4_0_X: https://github.com/appcelerator/titanium_mobile/pull/6747
  14. Ashraf Abu 2015-03-27

    [~jalter] Could you review my 4_0_X backport? And once everything is okay, could you go to https://github.com/appcelerator-modules/ti.map/pull/85 travis build to restart and see if it is successful.
  15. Jon Alter 2015-03-27

    [~msamah] merged and restarted the travis build.
  16. Ingo Muschenetz 2015-03-31

    Yes, if it's not already been updated.
  17. Jon Alter 2015-03-31

    And update https://github.com/appcelerator/titanium_releases/blob/master/titanium.json
  18. Ashraf Abu 2015-04-01

    [~jalter] PR for https://github.com/appcelerator/titanium_releases/blob/master/titanium.json -> https://github.com/appcelerator/titanium_releases/pull/6
  19. Jon Alter 2015-04-01

    [~msamah] Looks good, I merged it. In the future, you don't need to do a PR for titanium_releases ... just push your change up. Don't forget to update the module in the master branch: https://github.com/appcelerator/titanium_mobile/tree/master/support/module/packaged and maybe the 4_0_X branch as well... [~ingo] do we also want the latest ti.map for android in the 4_0_X branch?
  20. Ingo Muschenetz 2015-04-01

    [~jalter] yes, please
  21. Ashraf Abu 2015-04-02

    [~jalter] Ok. Noted for the titanium_releases. If you could review and merge them. Master PR: https://github.com/appcelerator/titanium_mobile/pull/6748 4_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/6749
  22. Jon Alter 2015-04-02

    [~msamah] Merged
  23. Ewan Harris 2015-04-21

    Verified using: Mac OSX 10.10.2 Appc Studio: 4.0.0.201504161435 Titanium SDK build: 4.0.0.v20150417113416 Appc CLI (NPM): 0.3.45 Appc CLI (Registry): 0.2.250 Samsung Galaxy S4 (4.4.4) Using the test code provided by Hieu built to device, when clicking 'About' the app no longer crashes. Closing ticket.
  24. Marian Kucharcik 2015-04-28

    Hello guys, can you please help me how to fix this bug? I use com.tripvi.drawerlayout module in my Android app, have map view in centerView created with parameter fragmentOnly:true, but application still crashes. I use Titanium Studio, build: 3.4.1.201410281727, Ti SDK 3.5.1, tested on Motorola Moto G(2nd Generation), Android 4.4.4 Thank you. Best regards, Marian Kucharcik
  25. Manojkumar Murugesan 2015-04-29

    Hi Marian, This issue was fixed with SDK 4.0.0. And you must go with the updated module here https://github.com/manumaticx/Ti.DrawerLayout
  26. Marian Kucharcik 2015-04-29

    Hi Manoj, I installed Appcelerator Platform Studio with SDK 4.0.0 RC, Ti.Drawer module 1.3.0, app no longer crashes with map, but I can't load map view - it throws error Unable to load map, screen with map is black. I tried create several keystores and add it to Android Developer console, but it's not working. Can you please help me with this? Thank you
  27. Marian Kucharcik 2015-04-29

    Hello Manoj, I changed parameter fragmentOnly to false in map view constructor, map view is working but I have to comment TiDrawer code so I can't use it as side menu... Can you please help me with this? Thank you
  28. Manojkumar Murugesan 2015-05-07

    Hi Hieu, This is still a issue - https://github.com/manumaticx/Ti.DrawerLayout/issues/31 Map view as center view works fine but placing map view on a wrapper view and set the same as center view, never let the map load.
        var TiDrawerLayout = require('com.tripvi.drawerlayout');
        var Map = require("ti.map");
        var win = Ti.UI.createWindow({
            backgroundColor : 'white'
        });
        var drawer = TiDrawerLayout.createDrawer();
        var menu = Ti.UI.createTableView({
            data : [{
                title : "Home"
            }, {
                title : "About"
            }]
        });
        var wrapperView = Ti.UI.createView({
            backgroundColor : 'orange',
        });
        wrapperView.add(Ti.UI.createLabel({
            top : 10,
            text : "I would like to place a list view or some other compoent here, now map never loads",
            color : "#fff"
        }));
        var mapview = Map.createView({
            bottom : 0,
            height : "50%",
            fragmentOnly : true
        });
        wrapperView.add(mapview);
        drawer.setLeftView(menu);
        drawer.setCenterView(wrapperView);
        win.add(drawer);
        win.open();
        
  29. Ingo Muschenetz 2015-05-07

    @Manoj can you please file a separate ticket for that issue?
  30. Manojkumar Murugesan 2015-05-07

    @Ingo Muschenetz, created a separate ticket here TIMOB-18876. I have been following this issue for a year, this makes me to stay away from the fancy drawer layout widget. Hope this can be fixed in the upcoming release.

JSON Source