Ti.App.addEventListener in webview on Android crashes app

You must Login before you can answer or comment on any questions.

I am having trouble creating an Ti.App.addEventListener in a webview. Am I missing something? When I try to run the following code, the app crashes (Titanium SDK 4.2 | Android APIs 2.3):

app.js:

var win = Titanium.UI.createWindow({ backgroundColor:'#330' });

var webview = Titanium.UI.createWebView({ url: 'test.html' });

win.open(); win.add(webview);


test.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> Test of titanium addEventListener <script> Titanium.App.addEventListener('hideWords',function(e) { // empty function }); </script> </body> </html>

— asked 2 years ago by brian kurzius
2 Comments
  • I dont think you can do that... does it work on the iphone?

    — commented 2 years ago by Aaron Saunders

  • It works fine on the iphone -- I released the app the few weeks ago and no bug reports.

    — commented 2 years ago by brian kurzius

2 Answers

A follow up for anyone else having the same problem. It appears that the Android emulator for 2.3 has a bug which causes issues with the webview. Try using APIs 2.2 or lower until a new emulator is released. Apparently Gingerbread on the device works properly. You can see more about this issue here:

http://code.google.com/p/android/issues/detail?id=12987

It is not clear what you are trying to do, but I think I would suggest the following approach.

  1. attach the eventListener to the webView, don't include it in the html code
  2. when the event is triggered, run some javascript code against the HTML in the webView to perform the desired actions; see Titanium.UI.WebView.evalJS
— answered 2 years ago by Aaron Saunders
answer permalink
1 Comment
  • That's worth trying but the Kitchen Sink does embed the eventListener in the html. Check out web_views.js and local_webview.html.

    — commented 2 years ago by brian kurzius

Your Answer

Think you can help? Login to answer this question!