When a WebView window returns to the top of the stack, the page resume event is triggered. This happens when an app is brought from the background, resumes from the lock screen, or when a user navigates back from a subsequent page.
If you return to the window using popWindow or popTo and pass a data parameter, the page can retrieve these parameters.
If the app's resume event occurs before the window's resume event, the event object also contains a resumeParams property. This property includes the parameters received when the app resumed.
In client versions 10.0.15 and later, the container provides the
pageResumeandappResumeevents. These events help distinguish the specific cause of aresumeevent. Theresumeevent combines two scenarios:appResume, which occurs when the client is brought from the background or resumes from the lock screen, andpageResume, which occurs when a window is displayed again after you navigate back from a subsequent page.The native Android
resumeandpauseevents cannot distinguish whether the app was sent to the background or a page was switched. For this reason, thepageResumeandpagePauseevents are implemented as callbacks recorded through JSAPI calls. These events apply only to switching between windows within the samesession. They do not apply to other methods that switch pages, such asstartApporchooseImage.
How to use the resume interface
document.addEventListener('resume', function(e) {
console.log("resumed");
}, false);Code example
The following example shows how to return data:
<h1>Click "Open New Page". Data is sent back to this page on return.</h1>
<a href="#" class="btn J_demo">Open New Page</a>
<script>
function ready(callback) {
// If jsbridge is already injected, call it directly.
if (window.AlipayJSBridge) {
callback && callback();
} else {
// If not, listen for the injection event.
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function() {
document.querySelector('a').addEventListener('click', function() {
AlipayJSBridge.call('pushWindow', {
url: location.pathname
});
});
document.addEventListener('back', function(e) {
e.preventDefault();
AlipayJSBridge.call('popWindow', {
data: {
from: location.href,
info: Date.now()
}
});
});
document.addEventListener('resume', function(event) {
alert('Content from the previous page: ' + JSON.stringify(event.data));
});
});
</script>API
Output parameters
The event handler receives an event parameter with the following properties:
Name | Type | Description |
data | Object | The content passed from |
resumeParams | Object | Contains the parameters received when the |