Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7808] Android: Webview reloads when removed and re-added. Regression from 1.7.5

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-05-03T17:33:12.000+0000
Affected Version/sRelease 1.8.0
Fix Version/sSprint 2012-05, Release 2.0.0
ComponentsAndroid
Labelsmodule_webview, qe-testadded
ReporterVarun Joshi
AssigneePing Wang
Created2012-02-24T14:11:47.000+0000
Updated2014-06-04T21:42:53.000+0000

Description

This is a regression. When you try to move a webview from one view to another on Android using Titanium SDK 1.8.x and further, the webview reloads. It doesn't do this on iOS using any Titanium SDK. And it doesn't do it on Android when using Ti SDK 1.7.x. The test case below shows that even removing the webview from a window and putting it back again makes it reload.
var win = Ti.UI.createWindow();

// It doesn't matter if the webview is created using html orurl
// When loaded, the webview shows the current timestamp.
var webview = Ti.UI.createWebView({
    html: '<html><head></head><body><script>var now = Date.now(); document.body.innerHTML = now;</script></body></html>'
});

var onload = function(){
    // Actually, we could see that the load event would fires twice on Android,
    // but I want to really prove that the content actually reloads
    webview.removeEventListener('load', onload);

    var before = webview.evalJS('now');

    // Just removing the webview and adding it back again makes it reload on Android when using Ti SDK 1.8.x
    win.remove(webview);
    win.add(webview);

    // Give Android time to breathe
    setTimeout(function(){
        var after = webview.evalJS('now');
        alert('The webview ' + (before == after ? "HASN'T" : "HAS") + ' reloaded!');
    }, 500);

};
webview.addEventListener('load', onload);

win.add(webview);
win.open();
The issue was raised by one of the Appcelerator Titans.

Comments

  1. Ping Wang 2012-03-05

    Another test case:
       
       var win = Ti.UI.createWindow({backgroundColor: 'black'});
       
       var webview = Ti.UI.createWebView({
           html: '<html><head></head><body><script>var now = Date.now(); document.body.innerHTML = now;</script></body></html>',
           top: 0,
           height: 300
       });
       
       webview.addEventListener('load', function(){
       	alert('The webview is loaded!');
       });
       
       var b = Ti.UI.createButton({
       	title: "remove and add webview",
       	top: 400
       });
       b.addEventListener("click", function(){
       	win.remove(webview);
       	win.add(webview);
       });
       
       var b2 = Ti.UI.createButton({
       	title: "remove and release and add webview",
       	top: 500
       });
       b2.addEventListener("click", function(){
       	win.remove(webview);
       	webview.release();
       	win.add(webview);
       });
       
       win.add(webview);
       win.add(b);
       win.add(b2);
       win.open();
       
    Testing steps: 1. run the above code 2. click "remove and add webview". should not see any alert dialog. 3. click "remove and release and add webview". should see the alert dialog.
  2. Dustin Hyde 2012-03-16

    Closing as Fixed. Used Ping's Code. Behaved as Expected: 1. app start: load event 2. 'Remove and add webview': no reload event. 3. 'remove and release and add webview': reload event SDK: 2.0.0.v20120316130302 Android: V8, Rhino Studio: 2.0.0.201203152033 OS: Snow Leopard Devices Tested: Nexus One 2.2.2
  3. Natalie Huynh 2012-05-03

    Open to update label

JSON Source