-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): Ti.App wrongly fires pause/resume events when opening/c…
…losing child windows (#10658) - Fixed bug where Ti.App wrongly fires pause/resume events when opening/closing child windows - Updated Ti.App docs to indicate Android supported these events since 7.5.0 - Modified to only fire a "resume" event after a "pause" like iOS - Changed "TiApplicationLifecycle" class' static variables to instance member variables. They don't need to be static. Fixes TIMOB-26746
- Loading branch information
1 parent
53524fc
commit bf6530e
Showing
4 changed files
with
121 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
/* eslint-env mocha */ | ||
/* global Ti */ | ||
/* eslint no-unused-expressions: "off" */ | ||
'use strict'; | ||
var should = require('./utilities/assertions'); | ||
|
||
describe('Titanium.App', function () { | ||
it.android('pause/resume events', function (finish) { | ||
this.timeout(5000); | ||
let wasPauseEventReceived = false; | ||
let wasResumeEventReceived = false; | ||
|
||
// Handle Ti.App pause/resume events. They happen when app is sent to background/foreground. | ||
// - "pause" event must be received before "paused" event. | ||
// - "resume" event must be received before "resumed" event. | ||
Ti.App.addEventListener('pause', function pauseEventHandler(e) { | ||
Ti.API.info('Received event: ' + e.type); | ||
Ti.App.removeEventListener(e.type, pauseEventHandler); | ||
wasPauseEventReceived = true; | ||
}); | ||
Ti.App.addEventListener('paused', function pausedEventHandler(e) { | ||
Ti.API.info('Received event: ' + e.type); | ||
Ti.App.removeEventListener(e.type, pausedEventHandler); | ||
should(wasPauseEventReceived).be.true; | ||
Ti.Android.currentActivity.startActivity(Ti.App.Android.launchIntent); // Resume this app. | ||
}); | ||
Ti.App.addEventListener('resume', function resumeEventHandler(e) { | ||
Ti.API.info('Received event: ' + e.type); | ||
Ti.App.removeEventListener(e.type, resumeEventHandler); | ||
wasResumeEventReceived = true; | ||
}); | ||
Ti.App.addEventListener('resumed', function resumedEventHandler(e) { | ||
Ti.API.info('Received event: ' + e.type); | ||
Ti.App.removeEventListener(e.type, resumedEventHandler); | ||
should(wasResumeEventReceived).be.true; | ||
finish(); | ||
}); | ||
|
||
// Navigate to the device's home screen. Equivalent to pressing the "home" button. | ||
// This should fire this app's "pause" and "paused" events. | ||
const homeIntent = Ti.Android.createIntent({ | ||
action: Ti.Android.ACTION_MAIN, | ||
}); | ||
homeIntent.addCategory(Ti.Android.CATEGORY_HOME); | ||
homeIntent.setFlags(Ti.Android.FLAG_ACTIVITY_NEW_TASK); | ||
Ti.Android.currentActivity.startActivity(homeIntent); | ||
}); | ||
}); |