Expected Behavior
The app launch, pressing the button shows another window with a search bar in a table, then pushing the hardware back button take us to the first window, then push again the button to open the window with the search bar again, needs to work and open the window with the search bar again
Actual Behavior
When I push the button to open the search bar window for the second time, the application crash and throw this message:
msg:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first
Steps to reproduce
- Push the button
- use hardware button to go back to the first screen
- Push the button again
- Crash
Test Case
var page1 = require("page1");
page1.win.open();
var win = Ti.UI.createWindow({
backgroundColor:"white",
navBarHidden:false
});
var button = Ti.UI.createButton({
title:"button"
});
win.add(button);
var page2 = require("page2");
button.addEventListener('click', function(){
page2.win.open();
})
exports.win = win;
var win = Ti.UI.createWindow({
backgroundColor : "white",
navBarHidden : false
});
var search = Ti.UI.createSearchBar();
var table = Ti.UI.createTableView({
search:search
});
win.add(table);
exports.win = win;
I/ActivityManager( 62): Starting: Intent { cmp=com.appcelerator.app283994/org.appcelerator.titanium.TiActivity (has extras) } from pid 412
D/AndroidRuntime( 412): Shutting down VM
W/dalvikvm( 412): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/TiApplication( 412): (main) [2630,9831] Sending event: exception on thread: main msg:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.; Titanium 1.9.0,2012/01/03 08:46,428293e
E/TiApplication( 412): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
E/TiApplication( 412): at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
E/TiApplication( 412): at android.view.ViewGroup.addView(ViewGroup.java:1871)
E/TiApplication( 412): at android.view.ViewGroup.addView(ViewGroup.java:1851)
E/TiApplication( 412): at ti.modules.titanium.ui.widget.TiUITableView.processProperties(TiUITableView.java:131)
E/TiApplication( 412): at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:641)
E/TiApplication( 412): at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:449)
E/TiApplication( 412): at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:441)
E/TiApplication( 412): at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:427)
E/TiApplication( 412): at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:456)
E/TiApplication( 412): at ti.modules.titanium.ui.ActivityWindowProxy.handleMessage(ActivityWindowProxy.java:81)
E/TiApplication( 412): at android.os.Handler.dispatchMessage(Handler.java:95)
E/TiApplication( 412): at android.os.Looper.loop(Looper.java:130)
E/TiApplication( 412): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/TiApplication( 412): at java.lang.reflect.Method.invokeNative(Native Method)
E/TiApplication( 412): at java.lang.reflect.Method.invoke(Method.java:507)
E/TiApplication( 412): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/TiApplication( 412): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/TiApplication( 412): at dalvik.system.NativeStart.main(Native Method)
I/ActivityManager( 62): Displayed com.appcelerator.app283994/org.appcelerator.titanium.TiActivity: +364ms
E/AndroidRuntime( 412): FATAL EXCEPTION: main
E/AndroidRuntime( 412): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
E/AndroidRuntime( 412): at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
E/AndroidRuntime( 412): at android.view.ViewGroup.addView(ViewGroup.java:1871)
E/AndroidRuntime( 412): at android.view.ViewGroup.addView(ViewGroup.java:1851)
E/AndroidRuntime( 412): at ti.modules.titanium.ui.widget.TiUITableView.processProperties(TiUITableView.java:131)
E/AndroidRuntime( 412): at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:641)
E/AndroidRuntime( 412): at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:449)
E/AndroidRuntime( 412): at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:441)
E/AndroidRuntime( 412): at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:427)
E/AndroidRuntime( 412): at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:456)
E/AndroidRuntime( 412): at ti.modules.titanium.ui.ActivityWindowProxy.handleMessage(ActivityWindowProxy.java:81)
E/AndroidRuntime( 412): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 412): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 412): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 412): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 412): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 412): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 412): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 412): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 62): Force finishing activity com.appcelerator.app283994/org.appcelerator.titanium.TiActivity
PR https://github.com/appcelerator/titanium_mobile/pull/2497
Environment used for verification - Tested with Titanium SDK: 2.2.0.v20120801170113 Tested with Titanium Studio: 2.1.1.201207271312 Device - Android Emulator 2.3.3 Machine OS - MAC 10.7.3
Occurs on: Titanium SDK: 2.1.2.v20120816171609 Titanium Studio: 2.1.2.201208192014 Device: Samsung GALAXY Note (2.3.6) Fixed with: SDK version: 2.2.0.v20120801170113
Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4758