我试图通过传递上下文通过广播接收器调用方法(postMessage),但不工作。
错误是什么?我尝试了很多东西,但仍然没有工作。
public class AlarmReceiver extends BroadcastReceiver implements
OnActivityResultListener {
public void onReceive(Context context, Intent intent) {
try {
controler(context);
} catch (Exception e) {
Toast.makeText(
context,
"There was an error somewhere",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
public void controler(Context context) {
String radioButtonName = MAinActivity.actionAlarmName(radioButtonName);
if (radioButtonName.equals("1")) {
// TODO
} else if (radioButtonName.equals("2")) {
postMessage(context);
}
}
public void postMessage(Context context) {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
// Yes button clicked
break;
case DialogInterface.BUTTON_NEGATIVE:
// No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Are you sure?")
.setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
}