简体   繁体   中英

Dialog doesn't appear when the app is in the background

When app goes to background this alert popup alert dialog..so the point is to get that popup alert everytime when aplication goes to background and alert user like didnt finish a job.

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();

}

This is thread part...

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;
        }

Dialogs only appear when your app has an activity on the foreground.

Instead of a dialog, what you can do is start an activity and give it the appearance of a dialog.

You can see how to do it here: Android Activity as a dialog

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM