Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4877] Android: activityIndicator does not show in app.js without setTimeout

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2017-07-10T22:04:20.000+0000
Affected Version/sRelease 1.7.2
Fix Version/sn/a
ComponentsAndroid
Labelstbs-1.9.0
ReporterJon Alter
AssigneeEric Merriman
Created2011-08-03T09:55:27.000+0000
Updated2017-07-10T22:04:29.000+0000

Description

In the code below, you will never see the activity indicator if you do not use setTimeout Step 1: run the code below Step 2: notice that you do not see an activity indicator or the blue window Step 3: uncomment the setTimeout Step 4: run the app again Step 5: notice that the activity indicator and blue window show as expected.
var win = Ti.UI.createWindow({
	backgroundColor: 'blue'
});

var actInd = Titanium.UI.createActivityIndicator({
	bottom:100, 
	height:50,
	width:10,
	style:Titanium.UI.iPhone.ActivityIndicatorStyle.PLAIN,
	font: {fontFamily:'Helvetica Neue', fontSize:15,fontWeight:'bold'},
	color: 'white',
	message: 'Loading...',
	width: 210
});

var loadingWin = Ti.UI.createWindow({
		backgroundImage: Ti.Platform.name == 'iPhone OS' ? 'Default.png':'default.png' ,
		fullscreen: true
});

loadingWin.open();
loadingWin.add(actInd);
actInd.show();

// setTimeout(function(){
	for(var i = 0; i<3000; i++){
		Ti.API.info(i);
	}
	loadingWin.close();
	actInd.hide();
	win.open();
// },0);

Workaround

Use setTimeout as shown in the example above.

Associated Helpdesk Ticket

http://appc.me/c/APP-571741

Comments

  1. Allen Yeung 2011-10-14

    Not much we can do here since it's an issue with JS multithreading. I would use the workaround as you suggested with setTimeout() or add an event listener for the 'open' event like:
       var win = Ti.UI.createWindow({
       	backgroundColor: 'blue'
       });
       
       var actInd = Titanium.UI.createActivityIndicator({
       	bottom:100, 
       	height:50,
       	width:10,
       	style:Titanium.UI.iPhone.ActivityIndicatorStyle.PLAIN,
       	font: {fontFamily:'Helvetica Neue', fontSize:15,fontWeight:'bold'},
       	color: 'white',
       	message: 'Loading...',
       	width: 210
       });
       
       var loadingWin = Ti.UI.createWindow({
       		backgroundImage: Ti.Platform.name == 'iPhone OS' ? 'Default.png':'default.png' ,
       		fullscreen: true
       });
       
       loadingWin.open();
       loadingWin.add(actInd);
       
       actInd.show();
       
       loadingWin.addEventListener('open', function () { 
       	for(var i = 0; i<1000; i++){
       		Ti.API.info(i);
       	}
       
       	loadingWin.close();
       	actInd.hide();
       	win.open();
       });
       
  2. Lee Morris 2017-07-10

    Closing ticket due to time passed and lack of progress for a number of years. Please open a new ticket if there are any problems.

JSON Source