public class ForceOfflineReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
dialogBuilder.setTitle("Warning");
dialogBuilder.setMessage("You are forced to be offline. Please try to login again.");
dialogBuilder.setCancelable(false);
dialogBuilder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCollector.finishAll();
Intent intent = new Intent(context,
LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.getWindow().setType(TYPE_SYSTEM_ALERT);
alertDialog.show();
}
}
当我单击按钮时,没有出现对话框。 日志是:
08-21 10:40:05.756 13851-13851 / com.project.ics.day0821rememberpassword V / BoostFramework:BoostFramework():mPerf = com.qualcomm.qti.Performance@c4322f2 08-21 10:40:05.757 13851-13851 / com.project.ics.day0821rememberpassword V / BoostFramework: BoostFramework():mPerf = com.qualcomm.qti.Performance@667cd43 08-21 10:41:06.499 13851-13851 / com.project.ics.day0821rememberpassword W / IInputConnectionWrapper:clearMetaKeyStates处于非活动状态 InputConnection 08-21 10:41:07.559 13851-13851 / com.project.ics.day0821rememberpassword I / Choreographer: 跳过57帧!应用程序可能在其上做了太多工作 主线。
github上的源代码: https://github.com/gowufang/AndroidStu/tree/master/Day0821RememberPassword
答案 0 :(得分:-1)
可能你没有设置当你按下按钮时执行的方法的名称,或者你拼写错了,我有这个问题,但后来我得到了它。(按钮的“onClick”属性名称是没有设置或设置错误)