小视频源码,按返回键两次退出

2020-10-13 17:43:21 浏览数 (1)

代码语言:javascript复制
// 按两次退出
var flag = 0;
function exitApp (){
  api.addEventListener({    
 name: 'keyback' 
          }, function(ret, err) {
 if (flag == 1) {
                  api.closeWidget({
 silent: true
                  });
              } 
 else {
                  flag = 1;
                  api.toast({
 msg: '再点一次退出应用',
 duration: 2000,
 location: 'bottom'
                  });
 setTimeout(function() {
                      flag = 0;
                  }, 2000);
              }
         })
}
  // 拦截Android的返回键,在首页点击返回键,提示退出应用
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                api.confirm({
                    title: '提示',
                    msg: '是否退出应用',
                    buttons: ['确定', '取消']
                }, function(ret, err) {
                    if (ret.buttonIndex == 1) {
                        // 关闭当前的主Widget,就可以实现推出APP的效果
                        api.closeWidget({
                            silent: true //直接退出,无需提示
                        });
                    }
                });
            });

0 人点赞