在ScreenLock上关闭“警报”对话框

如何解决在ScreenLock上关闭“警报”对话框

| 屏幕锁定和解锁后,我的警报对话框消失了。 1)在asynctask(内部类)中开始连接,此处的进度对话框开始说“请稍候...”。 2)连接完成后,将关闭ProgressDilog并显示警报消息。 因此,在此过程中,当我在启动连接时锁定屏幕时,不会显示警报消息,并且会显示以前状态下的相同活动。
alertBuilder = new AlertDialog.Builder(Registration.this);
alertBuilder.setMessage(Constants.TEXT_REGISTERED_SUCCESSFULLY);
alertBuilder.setCancelable(false);
alertBuilder.setPositiveButton(Constants.TEXT_OK,new android.content.DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog,int which) {
// TODO Auto-generated method stub
    Util.saveData(Registration.this);
    Intent thanksYouIntent = new Intent(Registration.this,ThankYouActivity.class);
    Registration.this.finish();
} });
alertBuilder.create().show();
这是我用于引发对话框的代码。我听说将对话框绑定到活动,所以我尝试像alertBuilder.create()。setOwnerActivity(RegistrationActivity.this)。这也没有显示任何结果。 我不清楚的一件事是当父活动暂停时正在运行Connection的内部asyncTask会发生什么情况。任何主体请帮助我。 提前致谢, 沙。     

解决方法

        如果错误,请纠正我。当我的观察到一个活动处于暂停状态时,相应的AsyncTask将停止。 因此,在我的情况下,当屏幕锁定时,asynctask的doInBackground中的连接已经开始执行。但是由于屏幕锁定原因,asyncTask已停止并且onPostExecute无法成功完成。处于onpostexecute的我的alertDialog没有显示。 \将保存连接的响应状态,并在屏幕上使用布尔检查解锁时调用oncreate时显示它。 下面是代码。这是巨大的,但是不能用来解释我的情况。
   private static boolean alertDialogDismissedUnExpectedly;
private static String _alertMessage; //alert Message is for saving the previous alert message displaying when screen is locked

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  //coding part

  _registerImageView.setOnClickListener(new OnClickListener() {//here the asynctask starts running on click
    private String _response;
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        _alertMessage = \"\";
        //post data for response
        String postcontent=\"Sucess\";
        if(Constants.LOG)Log.d(\"Content to post is :\",\"\"+postcontent);
        ResgiserAsyncTask asyncTask = new ResgiserAsyncTask(postcontent);
        asyncTask.execute(null);


   }
  if(alertDialogDismissedUnExpectedly && savedInstanceState != null){ // check for Alert Message dismissed unexpectedly

    if(_alertMessage == null ? true : _alertMessage.equalsIgnoreCase(\"\")){ //intialise the last state of alert message if no alert message is set

        _alertMessage = _Engine.get_returnMessage();//this is my engine where parsing is done,So i\'ll get the previous response of connection

    }

    if(_alertMessage != null){
        if(_alertMessage.equalsIgnoreCase(Constants.TEXT_REGISTERED_SUCCESSFULLY) || _alertMessage.equalsIgnoreCase(Constants.TEXT_SUCCESS)){//my success case

            raiseSuccessDialog();//this is internal method

        }else{//failure case

            raiseDialog(_alertMessage);//this is internal method

        }
    }

  }else{

    alertDialogDismissedUnExpectedly = false;
    _alertMessage = \"\";
  }
}

private class ResgiserAsyncTask extends AsyncTask{
    private String _postContent;
    private Document _document;
    public ResgiserAsyncTask(String postContent) {
        // TODO Auto-generated constructor stub
        alertDialogDismissedUnExpectedly = true;//set the coolean to true and make it false Clicklistener of alertDialog
        _postContent= postContent;
    }
    @Override
    protected Void doInBackground(Void... arg0) {
        // TODO Auto-generated method stub
        _document = Util.postPage(Constants.URL_REGISTRATION,_postContent,true);
        return null;
    }
    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        if(_document != null){

            String _response = _Engine.parseRegistration(_document);
            if(!Constants.TEXT_SUCCESS.equalsIgnoreCase(_response)){
                raiseDialog(_response);
            }else{

                raiseSuccessDialog();
            }

        }
    }

}

private void raiseSuccessDialog(){

        _alertMessage = Constants.TEXT_REGISTERED_SUCCESSFULLY;
        alertBuilder = new AlertDialog.Builder(Registration.this);
        alertBuilder.setMessage(Constants.TEXT_REGISTERED_SUCCESSFULLY);
        alertBuilder.setCancelable(false);
        alertBuilder.setPositiveButton(Constants.TEXT_OK,new android.content.DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog,int which) {
                // TODO Auto-generated method stub
                alertDialogDismissedUnExpectedly = false;
                Intent thanksYouIntent = new Intent(Registration.this,ThankYouActivity.class);
                startActivity(thanksYouIntent);
            }
        });
        alertBuilder.create().show();

}

private void raiseDialog(String message) {
        // TODO Auto-generated method stub
    _alertMessage  = message; // intialise the message to the raised dialog so that when screen is locked the alert can be displayed once again
    AlertDialog.Builder alertBuilder = new Builder(Registration.this);
        alertBuilder.setMessage(message);
        alertBuilder.setCancelable(false);
        alertBuilder.setPositiveButton(Constants.TEXT_OK,int which) {
                // TODO Auto-generated method stub
                alertDialogDismissedUnExpectedly = false;
            }
        });
        alertBuilder.create().show();

}
希望它对遇到同样问题的人有所帮助。     ,        覆盖
onCreateDialog()
以显示对话框。它会有所帮助。     ,        @sha  屏幕关闭期间会引发一些事件,您也需要对其进行控制。...链接http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-意图/鞋子有关此的一些示例     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-