当应用程序在后台时,不会显示对话框

时间:2017-12-01 13:36:12

标签: java android background-process

当应用程序进入后台此警报弹出警报对话框时,重点是每次应用程序进入后台时都会收到该弹出警报,并提醒用户没有完成作业。

public void alertIfStopNotPressed(){
    if(active){
        this.runOnUiThread(new Runnable() {
            public void run() {
                callDialog();
            }

        });
    }
}

public void callDialog(){
    AlertDialog.Builder dlg = new AlertDialog.Builder(this)
            .setTitle("UPOZORENJE!")
            .setMessage("Pritisnite STOP ukoliko ste završili sastanak")
            .setPositiveButton("U redu",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });

    dlg.create().show();

}

这是线程部分......

if (clicked == false) {

        if (thread == null) {
            //thread for checking if operator has pushed stop button
            thread = new Thread() {


                @Override
                public void run() {

                    try {

                            sleep(1500000);
                            alertIfStopNotPressed();
                        }


                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            };
            thread.start();
            clicked = true;
        }

1 个答案:

答案 0 :(得分:0)

仅当您的应用在前台有活动时才会显示对话框。

而不是对话框,你可以做的是启动一个活动并给它一个对话框的外观。

您可以在此处查看如何操作:Android Activity as a dialog