[TIMOB-18244] Android: MapView crashes within Fragments
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-03-30T19:42:25.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 4.0.0, Release 4.1.0 |
Components | Android |
Labels | Ti.Map, mapView |
Reporter | Manuel Lehner |
Assignee | Hieu Pham |
Created | 2014-12-16T16:10:43.000+0000 |
Updated | 2015-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).
We will need to update the ti.map API so that we pass it the parent fragment (or its ID) somehow.
Any ideas for workarounds - or a timeframe for a fix?
[~jda] I've placed this into triage.
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.
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:
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)
Test case:
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.
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:
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?
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?
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.
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 !!!
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?
[~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.
PR for 4_0_X: https://github.com/appcelerator/titanium_mobile/pull/6747
[~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.
[~msamah] merged and restarted the travis build.
Yes, if it's not already been updated.
And update https://github.com/appcelerator/titanium_releases/blob/master/titanium.json
[~jalter] PR for https://github.com/appcelerator/titanium_releases/blob/master/titanium.json -> https://github.com/appcelerator/titanium_releases/pull/6
[~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?
[~jalter] yes, please
[~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
[~msamah] Merged
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.
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
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
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
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
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.
@Manoj can you please file a separate ticket for that issue?
@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.