Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Two Tab Map Application Crashes on Android

$
0
0

I have a three tab application with two tabs containing a google map. Clicking on the first tab loads the first map no problem. The second map crashes the app upon loading. Here is the system info and some code snippets:

Using Ti SDK 3.4.1GA Crashes on Android Using Ti.MAP 2.2.2

I have looked around and apparently when having multiple map, one has to remove if from first view and add it to the second view so you always have only one active map. Is this correct?

mainWindow = Ti.UI.createWindow({
            title: 'first window'
        });
 
        mapWindow1 = Ti.UI.createWindow({
            title : 'First Map'
        });
        mapWindow2 = Ti.UI.createWindow({
            title : 'Second Map'
        });
tabGroup = Titanium.UI.createTabGroup();
 
        tab1 = Titanium.UI.createTab({
            window : mainWindow,
            title : 'Dashboard',
            icon : '/img/house@2x.png',
            backgroundColor : 'white',
        });
 
        tab2 = Titanium.UI.createTab({
            icon : '/img/globe@2x.png',
            title : 'ASPS Map',
            window : mapWindow1
        });
 
        tab3 = Titanium.UI.createTab({
            icon : '/img/transportMap@2x.png',
            title : 'Load Tracker',
            window : mapWindow2
        });
 
        tabGroup.addTab(tab1);
        tabGroup.addTab(tab2);
        tabGroup.addTab(tab3);
So in the focus event handler of the tab group I switch the maps. So if the first tab is clicked, i check the second window and if it has a map (the only thing i add to it is a map) then i remove it. When I do remove it, the app crashes!

I make sure that I have a var Map = require('ti.map') in my app.js and my map object is a singleton for the mapView class. Basically I don't instantiate a new mapObject every time, I reuse the old one by removing annotations from it, setting a new region and so forth.

tabGroup.addEventListener('focus', function(e) {
 
 
        if (e.index == 2) {
         if(mapWindow1.children.length > 0)
        {
            mapWindow1.remove(mapWindow1.children[0]);
        }
            var mapView1 = mapViewController.setupFirstMapView();
            mapWindow1.add(mapView1);
            mapView1 = null;
 
        } else if (e.index == 1) {
            var mapView2 = mapViewController.setupSecondMapView();
            mapView2.add(mapView2);
            mapView2 = null;
 
        }
    });
For the life of me I can't figure out what the problem is. So removing a map view for a tab that is no longer in focus crashes the app, i can't load the new map. I am getting convinced that this might be a bug in the latest release ? My code was working perfectly fine but now its not!

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>