When a webview interface returns to the top of stack again, such as it is evoked from background, screen is unlocked, or it return from the next page, the event of page resume (resume
) will be triggered.
If the interface is returned via popWindow or popTo and data parameter is delivered, the page can obtain data.
If the resume
of App takes place before resume
of the interface, the event will come with a resumeParams
containing parameters received during app resume
.
Note:
- For the clients above 10.0.15 version, the container newly adds the
pageResume
andappResume
events for the service to distinguish which case has triggeredresume
.- Page resume (
resume
)= Client being evoked from background, lock screen interface being restored (appResume
) + window being restored after returning from the next page (pageResume
).- Since whether Android native
resume
andpause
event are caused by pushed background or page switch cannot be distinguished, thepageResume
andpagePause
event are called back through the JSAPI calling record, and therefore only applicable to mutual switch among windows in the same session. The method that startApp and other clients directly switch pages is invalid, such aschooseImage
.
Use resume interface
document.addEventListener('resume', function(e) {
console.log("resumed");
}, false);
Code sample
The following example is the case with data when returning:
<h1>When click "Open new page" and then return, data will be brought to the page</h1>
<a href="#" class="btn J_demo">Open a new page</a>
<script>
function ready(callback) {
// Call directly if JSBridge has been injected
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Monitor the injected events if JSBridge hasn't been injected
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 ('contents brought when page rolls back: ' + JSON.stringify(event.data));
});
});
</script>
API
Output parameters
The event parameter of event handling function has the following attributes:
Name | Type | Description |
---|---|---|
data | object | The contents brought by popTo or popWindow in the current App instance. Data cannot be passed across appId. |
resumeParams | object | Contains parameters received during app resume . |