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