Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-274] Android: Composite View addView Not Forcing UI Thread

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:52:34.000+0000
Affected Version/sn/a
Fix Version/sRelease 0.8.1
ComponentsAndroid
Labelsandroid, defect
ReporterDon Thorp
AssigneeDon Thorp
Created2011-04-15T02:26:30.000+0000
Updated2011-04-17T01:52:34.000+0000

Description

This works fine in iPhone simulator but not in Android, the page first loads fine but when I click on the button2, the application would quit. If I comment out one line ( compositeView.addView(views[0],{left:0,top:5,height:30}); ) then it works even if I add the webview.
code:

var button2 = Titanium.UI.createButton({
            id:'button2',
            title:'Text'
        });
        button2.addEventListener('click',function(e)
        {
            webView = Titanium.UI.createWebView({url:'meters-text.html', name:'myview'});
            var views = Titanium.UI.currentWindow.getViews();
            var compositeView = Titanium.UI.createCompositeView();
            compositeView.addView(views[0],{left:0,top:5,height:30}); // emulator quits here
            compositeView.addView(webView,{top:40,left:0});
            Titanium.UI.currentWindow.addView(compositeView);
            Titanium.UI.currentWindow.showView(compositeView);
        })
Log shows the following:
[TRACE] W/dalvikvm( 1433): JNI WARNING: JNI method called with exception raised
[TRACE] W/dalvikvm( 1433): in Landroid/webkit/BrowserFrame;.stringByEvaluatingJavaScriptFromString (Ljava/lang/String;)Ljava/lang/String; (GetObjectClass)
[TRACE] W/dalvikvm( 1433): Pending exception is:
[TRACE] I/dalvikvm( 1433): Landroid/view/ViewRoot$CalledFromWrongThreadException;: Only the original thread that created a view hierarchy can touch its views.
[TRACE] I/dalvikvm( 1433): at android.view.ViewRoot.checkThread(ViewRoot.java:2440)
[TRACE] I/dalvikvm( 1433): at android.view.ViewRoot.requestLayout(ViewRoot.java:509)
[TRACE] I/dalvikvm( 1433): at android.view.View.requestLayout(View.java:7069)
[TRACE] I/dalvikvm( 1433): at android.view.View.setLayoutParams(View.java:4327)
[TRACE] I/dalvikvm( 1433): at org.appcelerator.titanium.module.ui.TitaniumCompositeView.addView(TitaniumCompositeView.java:120)
[TRACE] I/dalvikvm( 1433): at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
[TRACE] I/dalvikvm( 1433): at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
[TRACE] I/dalvikvm( 1433): at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:138)
[TRACE] I/dalvikvm( 1433): at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1174)
[TRACE] I/dalvikvm( 1433): at android.webkit.WebViewCore.access$900(WebViewCore.java:42)
[TRACE] I/dalvikvm( 1433): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:663)
[TRACE] I/dalvikvm( 1433): at android.os.Handler.dispatchMessage(Handler.java:99)
[TRACE] I/dalvikvm( 1433): at android.os.Looper.loop(Looper.java:123)
[TRACE] I/dalvikvm( 1433): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:462)
[TRACE] I/dalvikvm( 1433): at java.lang.Thread.run(Thread.java:1058)
[TRACE] I/dalvikvm( 1433): "WebViewCoreThread" prio=5 tid=17 NATIVE
[TRACE] I/dalvikvm( 1433): | group="main" sCount=0 dsCount=0 s=0 obj=0x4365a890
[TRACE] I/dalvikvm( 1433): | sysTid=1444 nice=0 sched=0/0 handle=1750584
[TRACE] I/dalvikvm( 1433): at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
[TRACE] I/dalvikvm( 1433): at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
[TRACE] I/dalvikvm( 1433): at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:138)
[TRACE] I/dalvikvm( 1433): at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1174)
[TRACE] I/dalvikvm( 1433): at android.webkit.WebViewCore.access$900(WebViewCore.java:42)
[TRACE] I/dalvikvm( 1433): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:663)
[TRACE] I/dalvikvm( 1433): at android.os.Handler.dispatchMessage(Handler.java:99)
[TRACE] I/dalvikvm( 1433): at android.os.Looper.loop(Looper.java:123)
[TRACE] I/dalvikvm( 1433): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:462)
[TRACE] I/dalvikvm( 1433): at java.lang.Thread.run(Thread.java:1058)
[TRACE] I/dalvikvm( 1433):
[TRACE] E/dalvikvm( 1433): VM aborting
[TRACE] I/DEBUG ( 555): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
[TRACE] I/DEBUG ( 555): Build fingerprint: 'generic/sdk/generic/:1.5/CUPCAKE/150240:eng/test-keys'
[TRACE] I/DEBUG ( 555): pid: 1433, tid: 1444 >>> com.SelfService <<<
[TRACE] I/DEBUG ( 555): signal 11 (SIGSEGV), fault addr deadd00d
[TRACE] I/DEBUG ( 555): r0 00000328 r1 80000000 r2 0000000c r3 00000026
[TRACE] I/DEBUG ( 555): r4 deadd00d r5 43678ea8 r6 ad083e10 r7 fffe6588
[TRACE] I/DEBUG ( 555): r8 44dc7da0 r9 41047e18 10 41047e04 fp 00000001
[TRACE] I/DEBUG ( 555): ip ad083eec sp 44dc6018 lr afe13e4d pc ad03b5c2 cpsr 20000030
[TRACE] I/DEBUG ( 555): [#00](/projects/32238/tickets/00 "Ticket #00") pc 0003b5c2 /system/lib/libdvm.so
......
[TRACE] I/DEBUG ( 555): [#29](/projects/32238/tickets/29 "Ticket #29") pc 0000f3f4 /system/lib/libc.so
[TRACE] I/DEBUG ( 555): stack:
[TRACE] I/DEBUG ( 555): 44dc5fd8 00000005
[TRACE] I/DEBUG ( 555): 44dc5fdc 00000000
[TRACE] I/DEBUG ( 555): 44dc5fe0 afe39f90
[TRACE] I/DEBUG ( 555): 44dc5fe4 afe39fe4
[TRACE] I/DEBUG ( 555): 44dc5fe8 00000000
[TRACE] I/DEBUG ( 555): 44dc5fec afe13e4d /system/lib/libc.so
[TRACE] I/DEBUG ( 555): 44dc5ff0 001abbf8 [heap]
[TRACE] I/DEBUG ( 555): 44dc5ff4 afe12e69 /system/lib/libc.so
[TRACE] I/DEBUG ( 555): 44dc5ff8 fffe6588
[TRACE] I/DEBUG ( 555): 44dc5ffc ad083e10
[TRACE] I/DEBUG ( 555): 44dc6000 43678ea8
[TRACE] I/DEBUG ( 555): 44dc6004 ad083e10
[TRACE] I/DEBUG ( 555): 44dc6008 fffe6588
[TRACE] I/DEBUG ( 555): 44dc600c afe12ecd /system/lib/libc.so
[TRACE] I/DEBUG ( 555): 44dc6010 df002777
[TRACE] I/DEBUG ( 555): 44dc6014 e3a070ad
[TRACE] I/DEBUG ( 555): [#00](/projects/32238/tickets/00 "Ticket #00") 44dc6018 00000001
[TRACE] I/DEBUG ( 555): 44dc601c ad02deb3 /system/lib/libdvm.so
[TRACE] I/DEBUG ( 555): [#01](/projects/32238/tickets/01 "Ticket #01") 44dc6020 ad083e10
[TRACE] I/DEBUG ( 555): 44dc6024 ad02e2b9 /system/lib/libdvm.so
[TRACE] I/ActivityManager( 583): Process com.SelfService (pid 1433) has died.
[TRACE] I/WindowManager( 583): WIN DEATH: Window{436dd0a0 com.SelfService/com.SelfService.SelfserviceActivity paused=false}
[TRACE] W/InputManagerService( 583): Got RemoteException sending setActive(false) notification to pid 1433 uid 10019
[TRACE] D/Zygote ( 557): Process 1433 terminated by signal (11)

Comments

  1. Don Thorp 2011-04-15

    (from [58f4533ebecefc012ce636453ed2d6ab36d3102f]) [#274 state:resolved] moved addView to the UI thread. The example in the ticket won't work because it's trying to add view[0] into another view, which is not allowed after it's been viewed. http://github.com/appcelerator/titanium_mobile/commit/58f4533ebecefc012ce636453ed2d6ab36d3102f"> http://github.com/appcelerator/titanium_mobile/commit/58f4533ebecef...

JSON Source