0
votes

I'm refactoring an app written for iOS to Android. Unfortunately, the former dev didn't use Titanium properly (no MVC separation, tons of global variables and other nightmarish scenarios...). I couldn't turn the app to a MVC compliant one, but i managed to make it run on Android. The only big trouble i get is with ANR situations.

Here my config details:

Application type: mobile Titanium SDK: Titanium Command-Line Interface, CLI version 3.3.0, Titanium SDK version 3.2.3.GA Platform & version: Android 2.3.6 Device: Android Samsung GT-I9070 Host Operating System: OSX 10.8.5 Titanium Studio: Titanium Studio, build: 3.3.0.201407100905

Code that causes the ANR scenario:

//app.js

var winPrincipal = Ti.UI.createWindow();


//menu.js exceprt:
// clicking this btn the main content is replaced with elenco_damande()
menuUI.mieDomandeBtn.addEventListener('click', function(e) {
       if (menuUI.mainView.getVisible()) {
           var viewTmp = elenco_damande();
           container.removeAllChildren();
           container.add(viewTmp);
           mainContainer.setRight(0);
        menuUI.mainView.nascondi();
       } else {
           menuUI.mainView.mostra();
       }
   });


//elenco_damande
//mainContent is replaced with another view
contentDomanda.addEventListener('click',function(){
               var viewRispondi = elenco_domande_rispondi(this.id, this._titolo, this._descrizione, this._ideas, this._status,this._attachment);               
               winPrincipal.add(viewRispondi);
           });


//elenco_domande_rispondi:
//clicking this item causes the view to close and go back to the previuos screen

   imgButtonBack.addEventListener('click', function(){
       winPrincipal.remove(mainView);
       mainView=null;
   });

Everything is fine when i open the first question and i go back to previous screen, but opening next contents cause ANR to be risen.

[INFO] :   I/APACHE HTTP (thCr=9) - NafHttpAuthStrategyDefault: (thUse=228)    cached value : gbaSupportIsPossible=false
[INFO] :   I/APACHE HTTP (thCr=9) - NafHttpAuthStrategyDefault: (thUse=228) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
[INFO] :   I/APACHE HTTP (thCr=228) - NafRequestExecutorWrapperRedirectionHandler: (thUse=228)    It isn't GBA flow, redirection responses are not handled.
[WARN] :   TiUIScrollView: (main) [582625,582625] Scroll direction could not be determined based on the provided view properties. Default VERTICAL scroll direction being used. Use the 'scrollType' property to explicitly set the scrolling direction.
[WARN] :   TiUIScrollView: (main) [2697,585322] Scroll direction could not be determined based on the provided view properties. Default VERTICAL scroll direction being used. Use the 'scrollType' property to explicitly set the scrolling direction.
[WARN] :   TiUIScrollView: (main) [3416,588738] Scroll direction could not be determined based on the provided view properties. Default VERTICAL scroll direction being used. Use the 'scrollType' property to explicitly set the scrolling direction.
[INFO] :   I/APACHE HTTP (thCr=9) - NafHttpAuthStrategyDefault: (thUse=229)    cached value : gbaSupportIsPossible=false
[INFO] :   I/APACHE HTTP (thCr=9) - NafHttpAuthStrategyDefault: (thUse=229) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
[INFO] :   I/APACHE HTTP (thCr=229) - NafRequestExecutorWrapperRedirectionHandler: (thUse=229)    It isn't GBA flow, redirection responses are not handled.
[INFO] :   I/APACHE HTTP (thCr=9) - NafHttpAuthStrategyDefault: (thUse=230)    cached value : gbaSupportIsPossible=false
[INFO] :   I/APACHE HTTP (thCr=9) - NafHttpAuthStrategyDefault: (thUse=230) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
[INFO] :   I/APACHE HTTP (thCr=230) - NafRequestExecutorWrapperRedirectionHandler: (thUse=230)    It isn't GBA flow, redirection responses are not handled.
[INFO] :   in utf-8 onload for GET badgenumber = 0
[INFO] :   I/APACHE HTTP (thCr=9) - NafHttpAuthStrategyDefault: (thUse=231)    cached value : gbaSupportIsPossible=false
[INFO] :   I/APACHE HTTP (thCr=9) - NafHttpAuthStrategyDefault: (thUse=231) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
[INFO] :   I/APACHE HTTP (thCr=231) - NafRequestExecutorWrapperRedirectionHandler: (thUse=231)    It isn't GBA flow, redirection responses are not handled.
[WARN] :   TiUIScrollView: (main) [2954,591692] Scroll direction could not be determined based on the provided view properties. Default VERTICAL scroll direction being used. Use the 'scrollType' property to explicitly set the scrolling direction.
[INFO] :   in utf-8 onload for GET setReadAnswer = null
[INFO] :   dalvikvm: threadid=4: reacting to signal 3
[INFO] :   dalvikvm: Wrote stack traces to '/data/anr/traces.txt'

traces.txt: http://pastebin.com/7f9VJmCG traces.txt.bugreport : http://pastebin.com/VSsM2jxP

Thanks for the help Lorenzo

1
It's hard to say by the code you've pasted. Because it seems like there is much more behind. What I can advice you is to try and debug it using logs and see what the last log that is printing to see where it get stuck. Remember that javascript is single threaded, and that thread is what interacts with your UI, so you need to find out which process blocks the thread.developer82

1 Answers

0
votes

It ended up that was something related to XML traversing... here's my solution (workaround, better saying): Convert XML to string then back to XML and get the item i need:

var tmp1 = Ti.XML.serializeToString(previousInvalidXML);
var tmp2 = Ti.XML.parseString(tmp1);
tmp2 = requestListResponseRequest.getElementsByTagName('idea');

Weird but good. Hope this may help someone else out here :)