ap.offAppPause 移除应用压后台事件的监听
优质
小牛编辑
124浏览
2023-12-01
ap.offAppPause(CALLBACK)
移除应用压后台事件的监听。
代码示例
<script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.inc.min.js"></script>
<h2 class="am-ft-center">点击 Home 键回到手机桌面</h2>
<script>
var output = document.querySelector('#J_output');
var appPauseHandler = function(){
time = Date.now();
ap.offAppPause(appPauseHandler);
};
var appResumeHandler = function(){
time = Date.now() - time;
ap.alert('应用在后台运行了' + time/1000 + 's');
ap.offAppPause(appResumeHandler);
};
var time;
ap.onAppPause(appPauseHandler);
ap.onAppResume(appResumeHandler);
</script>