Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14913] Android: SDK 3.1.2 heavyweight/lightweight window confusion

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-08-22T18:22:51.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 18, 2013 Sprint 18 API, Release 3.1.3, Release 3.2.0
ComponentsAndroid
Labels3.1.2, actionbar, activity, android, qe-testadded, regression, window
ReporterMark Mokryn
AssigneePing Wang
Created2013-08-18T22:17:02.000+0000
Updated2013-09-04T10:23:06.000+0000

Description

Apparently with SDK 3.1.2.GA, Titanium thinks a lightweight window has an associated activity and action bar. In SDK 3.1.1.GA, window.getActivity() returns null for lightweight windows, but not in 3.1.2.GA index.xml:
<Alloy>
	<!-- if we add navBarHidden="false" to Window element it becomes heavyweight,
	but if we leave it out 3.1.2 *thinks* it's heavyweight, and crashes. 3.1.1 treats it as lightweight
	-->
	<Window class="container" id="win1">
		<Label id="label1">Just a label</Label>
	</Window>
</Alloy>
index.js:
function homeIconClicked() {
	alert('clicked');
}

$.win1.addEventListener('open', function() {
	if (OS_ANDROID) {
		var activity = $.win1.getActivity();
		if (!activity){
			alert('no activity for this window');
			return;
		}
		var actionBar = activity.actionBar;
		if (actionBar){
			actionBar.title = 'Window 1';
			actionBar.displayHomeAsUp = true;
			actionBar.onHomeIconItemSelected = homeIconClicked;
		} else {
			alert('no action bar');
		}
	}	
});
$.win1.open();
snippet from tiapp.xml:
<android xmlns:android="http://schemas.android.com/apk/res/android">
    <tool-api-level>17</tool-api-level>
    <manifest android:installLocation="preferExternal">
        <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="16"/>
    </manifest>
</android>

Comments

  1. Tim Poulsen 2013-08-20

    According to the release notes, TIMOB-13796 was addressed in 3.1.2, which is supposed to have made all Android windows heavyweight. However, I can reproduce your crash using your sample. I can solve the crash by forcing the window to be heavyweight (with navBarHidden or similar set as a window property)
  2. Mark Mokryn 2013-08-20

    Looking through the code, 3.1.2 does not make all windows heavyweight: Look at postOnCreate in TiApplication.java - USE_LEGACY_WINDOW = true;
  3. Ping Wang 2013-08-21

    For 3.1.2, lightweight windows are still there. We will deprecate LW windows in 3.2.0.
  4. Ping Wang 2013-08-21

    Test case:
       -------------------app.js-------------------------
       var win = Ti.UI.createWindow({
       	backgroundColor: 'yellow',
       	url: 'windowURL.js'
       });
       
       win.addEventListener('open', function(){
       	var activity = win.getActivity();
       	Ti.API.info("********************** activity = " + activity);
       	if (!activity) {
       		alert("no activity for window");
       	}
       })
       
       win.open();
       
       --------------------windowURL.js-------------------
       var win = Ti.UI.currentWindow;
       
       setTimeout(function(){
       	win.backgroundColor = 'red';
       }, 1000);
       
       
    For FR, please add
    <property name="ti.android.useLegacyWindow" type="bool">true</property>
    to the tiapp.xml and run the above test case. Should see an alert and the window background color changes from yellow to red. Please also test KS->Base UI->Menu(Android).
  5. Ping Wang 2013-08-21

    PR: https://github.com/appcelerator/titanium_mobile/pull/4590
  6. Ping Wang 2013-08-22

    3_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/4597
  7. Priya Agarwal 2013-08-23

    Verified Environment: Studio: 3.1.3.201308201707 Sdk: 3.1.3.v20130822140128 acs:1.0.6 alloy:1.2.1-cr titanium:3.1.2 OS: OSX 10.8.4 Devices:Android Nexus 7(4.3),Samsung Duos(2.3.6),Nexus 7(4.2.1) Used the code given above for alloy project it was reproducible on 3.1.2.GA but now it is resolved. window.getActivity() returns null for lightweight windows in 3.1.3.v20130822140128. but in 3.1.2.GA window.getActivity() returns null for lightweight windows "I/TiAPI(15727): ***********{"bubbleParent":true,"actionBar":{"bubbleParent":true,"title":null}}". Issue is resolved now as window.getActivity() returns null for lightweight windows using 3.1.3.v20130822140128 sdk. Thus closing as fixed.

JSON Source