我有一个程序时,它的前景几秒钟后,负责显示AlertDialog:如何显示AlertDialog当应用程序在前台Android?
ActivityManager am = (ActivityManager) getSystemServ();
if (am != null) {
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
if (taskInfo != null && !taskInfo.isEmpty()) {
if (taskInfo.get(0) != null && taskInfo.get(0).topActivity != null) {
if (!MY_CLASS_NAME.equalsIgnoreCase(taskInfo.get(0).topActivity.getClassName())) {
new AlertDialog.Builder(this).setMessage("AAAAAAAAAAAAAAAAAAAAAAAAAAAA?")
.setTitle("Message").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which){
}
}).show();
}
}
}
}
但是当应用到前景AlertDialog没有显示!请帮助我!谢谢!
你确定你的id-else条件正确导致AlertDialog吗?你能记录任何消息来验证条件工作正常吗? – waqaslam
你在哪里运行这段代码?在活动或服务? – alexanderblom
@alexanderblom 在服务:我哈瓦的TimerTask timer.scheduleAtFixedRate(新的TimerTask(){ showAlertDialog();} – user1184715