应用程序在后台时不显示对话框
Dialog doesn't appear when the app is in the background
当应用程序进入后台时,此警报弹出警报对话框..所以重点是每次当应用程序进入后台并提醒用户没有完成作业时弹出警报。
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;
}
仅当您的应用在前台有 activity 时才会出现对话框。
除了对话框,您可以启动一个 activity 并赋予它对话框的外观。
您可以在此处查看操作方法:Android Activity as a dialog
当应用程序进入后台时,此警报弹出警报对话框..所以重点是每次当应用程序进入后台并提醒用户没有完成作业时弹出警报。
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;
}
仅当您的应用在前台有 activity 时才会出现对话框。
除了对话框,您可以启动一个 activity 并赋予它对话框的外观。
您可以在此处查看操作方法:Android Activity as a dialog