Android Question B4A.CallSub Locking up

cbanks

Active Member
Licensed User
Longtime User
When I tap on a paragraph with the following code in the web page in my app, it takes a long time to highlight or just locks up the app. What is wrong? It used to work fine.

Code: Copy
    <html>
    <head>

<link rel="stylesheet" href="../../style.css?dummy=" & DateTime.Now/>

<script type="text/javascript">
function createListener(){
    //    code to add the highlight on click event listener
    document.addEventListener('click', function(event){
        var element=event.target;
        var tagName=element.tagName.toLowerCase();
       
        if(tagName!=='div'){
            while(tagName!=='body' && (tagName!=='a' || element.name!=='')){
                //    find the clicked element's parent 'div' element to highlight (if the clicked element has no parent 'div' element then the loop will stop when the 'body' element is reached)
                element=element.parentNode;
                tagName=element.tagName.toLowerCase();
                if(tagName==='div'){
                    break;
                }
            }
        }
        if(tagName==='div'){
            if(element.className==='highlight'){
                element.className='';
            } else {
                element.className='highlight';
paragraph=element.innerText;
            }
        }

        var modifiedElements=document.getElementsByClassName('highlight'), text;
        if(modifiedElements.length>0){
            //    some elements have been highlighted so send the entire modofied page to a B4A Sub SaveHtml
            text=document.documentElement.outerHTML;
        } else {
            //    the page currently contains no highlighted elements send an empty string to the B4A Sub SaveHtml to indicate there is no need to save the page
            text=document.documentElement.outerHTML;
        }
        B4A.CallSub('SaveHtml', true, text);
while(tagName!=='a'){
    B4A.CallSub('SaveParagraph', true, paragraph);
    if(tagName==='div'){
        break;
    }
}
    }, false);
}
</script>

<title>Moroni 5</title>
    </head>
    <body onLoad="createListener()">

    <a href="../index.html" class="classname" style="width:auto;">Book of Mormon</a> <a href="index.html" class="classname" style="width:auto;">Moroni</a> Chapter 5
</div><p>
<a href="http://alumnihighschool.net/scriptures/bm/Moroni_5.mp3"><img src="../audio.jpg"></a>
</div><p>

</div><p> <i>The mode of administering the sacramental wine is set forth. [Between A.D. 400 and 421]</i>
</div><p> <div id="5: 1"></a>&#160;<href="5.html#5">1</a>&#160;The <a href="../../helps/morofn.html#5: 1a">manner</font></a> of administering the wine-Behold, they took the cup, and said:
</div><p> <div id="5: 2"></a>&#160;<href="5.html#5">2</a>&#160;O God, the Eternal Father, we ask thee, in the name of thy Son, Jesus Christ, to bless and sanctify this <a href="../../helps/morofn.html#5: 2a">wine</font></a> to the souls of all those who drink of it, that they may do it in <a href="../../helps/morofn.html#5: 2b">remembrance</font></a> of the <a href="../../helps/morofn.html#5: 2c">blood</font></a> of thy Son, which was shed for them; that they may witness unto thee, O God, the Eternal Father, that they do always remember him, that they may have his <a href="../../helps/morofn.html#5: 2d">Spirit</font></a> to be with them. Amen.

</body>
</html>
 
So do you mean remove the code from Sub SaveParagraph(paragraph As String) and Sub SaveHtml(Html As String) from within my app?

I'm not sure what code I need to add to log a message. Do you mind helping me with that? Thanks for your reply!

I thought the problem may have started when I moved from the FlingableWebView library to the AJWebKit library, but I reverted my code back to the FlingableWebView library and it still takes a long time for it to highlight a paragraph when I tap on the paragraph and it locks up at times when trying to highlight paragraphs.

When I remove the code below then the app no longer hesitates or locks up when highlighting, of course it it doesn't do what I need to in my app either, but.

Code: Copy
        B4A.CallSub('SaveHtml', true, text);
while(tagName!=='a'){
    B4A.CallSub('SaveParagraph', true, paragraph);
    if(tagName==='div'){
        break;
    }
}
 
Last edited:
Upvote 0
What do I need to change to make it work again? It used to work just fine with the code that I've posted. What changed?
 
Upvote 0
Back
Top