Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15038] Android: Unable to pop an alert while coming back to foreground

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2013-09-09T17:28:34.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 19, 2013 Sprint 19 API, Release 3.1.3, Release 3.2.0
ComponentsAndroid
Labelsn/a
ReporterEduardo Gomez
AssigneeVishal Duggal
Created2013-09-04T16:45:54.000+0000
Updated2013-09-10T10:23:52.000+0000

Description

Issue

Android pause and resume events does not play nice on 3.1.2.GA. Noticeable by just to pop up an customized alert on launch of the app and whenever user come from background to foreground. User need to pop up an alert while coming back to foreground. Forgive me if I've missed something obvious but when I tested it out on 3.2.0.v20130830182135 SDK does not exhibit the issue. Looks like getActivity() is being fired slightly different and is used along with Window-Open method since docs mention: "The activity is not created until the window is opened. When a window is created, its activity property refers to an empty JavaScript object." Furthermore: "When the Don't keep activities option is enabled, the lifecycle of the activity is different from the normal case. Whenever the user leaves an activity, such as backgrounding the app using the HOME button, this activity is destroyed by Android, which calls onDestroy. In the normal case, onStop would be called and the activity would not be destroyed. Later, when the user goes back to that activity, this activity will be recreated, which calls onCreate. In the normal case, since the activity is not destroyed, onRestart would be called instead."

Tested on

This was tested in device with Android 4.1.2 (S3) and 2.3.5 (Droid Razr).

Steps to reproduce

(1) From window 1 go to --> window 2 (2) Press Home (watch output logs) (3) Again click the app icon. (4) Expected ( Alert msg to pop up ) although no alerts appears.

3.1.2.GA

On first attempt to get value of the activity, no logs are printed. User have to go back window 1 (via back button) and open window 2 so resume state can be registered, so to speak.
09-04 11:25:08.331: I/TiAPI(7452):   RED WINDOW - PAUSED 
09-04 11:25:08.409: D/Window(7452): Checkpoint: postWindowCreated()
09-04 11:25:08.417: I/TiAPI(7452):   BLUE WINDOW OPENED
09-04 11:25:08.432: I/TiAPI(7452):   BLUE WINDOW - RESUME 
09-04 11:25:08.432: I/ALERT(7452): (KrollRuntimeThread) [3388,26746]  BLUE WINDOW - RESUME 

3.2.0.v20130830182135

When user follows steps to reproduce activity states are fired properly.
09-04 10:59:57.328: I/TiAPI(5889):   BLUE WINDOW OPENED
09-04 10:59:57.344: I/TiAPI(5889):   BLUE WINDOW - RESUME 
09-04 10:59:57.344: I/ALERT(5889): (KrollRuntimeThread) [27114,27114]  BLUE WINDOW - RESUME 

Snippet

- app.js
function destroy() {
	//Was the app destroyed correctly
	Ti.API.info(" ### STATE: DESTROY");
}

Ti.Android.currentActivity.addEventListener("destroy", destroy);

//Simple UI - my root window ...
var window = Ti.UI.createWindow({
	backgroundColor : 'red',
	exitOnClose : true,
	fullscreen : false,
	//modal: true,
	navBarHidden : false
});
window.addEventListener('open', function() {
	Ti.API.info(' RED WINDOW OPENED');
	window.getActivity().addEventListener('pause', function(e) {
		Ti.API.info(' RED WINDOW - PAUSED ');
		//alert(' RED WINDOW - PAUSED ');
	});
	window.getActivity().addEventListener('resume', function(e) {
		Ti.API.info(' RED WINDOW - RESUME ');
		alert(' RED WINDOW - RESUME ');
	});
});
window.addEventListener('click', function() {
	var win = require('window')();
	win.open();
});
window.open(); 
- window.js
function object() {
	var window = Ti.UI.createWindow({
		backgroundColor : 'blue',
		exitOnClose : false,
		fullscreen : false,
		//modal: true,
		navBarHidden : false
	});

	window.addEventListener('open', function() {
		Ti.API.info(' BLUE WINDOW OPENED');
		window.getActivity().addEventListener('pause', function(e) {
			Ti.API.info(' BLUE WINDOW - PAUSED ');
			//alert(' BLUE WINDOW - PAUSED ');
		});
		window.getActivity().addEventListener('resume', function(e) {
			Ti.API.info(' BLUE WINDOW - RESUME ');
			alert(' BLUE WINDOW - RESUME ');
		});
	});

	window.addEventListener('click', function() {
		Ti.API.info(' BLUE WINDOW CLICKED');
		//alert(' BLUE WINDOW CLICKED');
	});

	return window;
}

module.exports = object;

Comments

  1. Ingo Muschenetz 2013-09-09

    This appears to have been fixed as a side effect of another issue.
  2. Dhirendra Jha 2013-09-10

    Test Environment - Appc Studio: 3.1.3.201309072408 SDK: 3.1.3.v20130909192251 acs: 1.0.6 Alloy: 1.2.2-beta titanium: 3.1.2 titanium-code-processor: 1.0.2 Devices: Nexus 7 (v4.3), Galaxy Note (v2.3.6) Followed the steps and used the same code mentioned in the issue. Now Alert popup appears on coming back to foreground. See below the log details - Nexus 7 (v4.3), Nexus 4 (v4.0.4) -------------------------------------------- 09-10 15:27:57.484: I/TiAPI(16603): BLUE WINDOW OPENED 09-10 15:27:57.484: I/TiAPI(16603): BLUE WINDOW - RESUME 09-10 15:27:57.484: I/ALERT(16603): (KrollRuntimeThread) [87,5087] BLUE WINDOW - RESUME 09-10 15:28:09.856: I/TiAPI(16603): BLUE WINDOW - PAUSED 09-10 15:28:24.009: I/TiAPI(16603): BLUE WINDOW - RESUME 09-10 15:28:24.009: I/ALERT(16603): (KrollRuntimeThread) [25982,31606] BLUE WINDOW - RESUME ------------------------- Samsung Galaxy Note (v2.3.6) ------------------------------------------------- 09-10 14:56:07.670: I/TiAPI(5694): BLUE WINDOW OPENED 09-10 14:56:15.590: I/TiAPI(5694): BLUE WINDOW - PAUSED 09-10 14:56:32.330: I/TiAPI(5694): BLUE WINDOW - RESUME 09-10 14:56:32.330: I/ALERT(5694): (KrollRuntimeThread) [38415,38702] BLUE WINDOW - RESUME ------------------------------------ Tested this issue using SDK 3.1.3.v20130909192251 build and working as expected. Hence closing this issue.

JSON Source