サービスからBroadcast
を送信してから、内部のBroadcastReceiver
クラスから返信します。私はいくつかのロジックに基づいてAlertDialog
を示さなければならないが、それをやろうとしている間、私はこのランタイムエラーを取得しています:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Getting 'あなたはこのアクティビティでTheme.AppCompatテーマ(または子孫)を使用する必要があります。' BroadcastReceiverからAlertDialogを表示しようとしています
ここMyBroadcastReceiver
クラスです:
public class MyBroadcastReceiver extends BroadcastReceiver {
public MyBroadcastReceiver(){
super();
}
@Override public void onReceive(final Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals(getString(R.string.broadcast_id))) {
Intent intent1 = new Intent(MyService.this, MainActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
@Override
public void run() {
if (someCondition) {
android.support.v7.app.AlertDialog.Builder builder1 = new android.support.v7.app.AlertDialog.Builder(getBaseContext());
builder1.setView(R.layout.dialog);
builder1.setPositiveButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent notificationIntent = new Intent(getBaseContext(), Notification.class);
notificationIntent.putExtra(Notification.NOTIFICATION, getNotificationGame());
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), m, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, finalFutureInMillis, pendingIntent);
postMethod(MainActivity.name, MainActivity.uidOfProfilePic, String.valueOf(MainActivity.currentLatDouble), String.valueOf(MainActivity.currentLngDouble), null, s, v, sA, requestID, user.getUid(), nP);
dialog.cancel();
}
});
final android.support.v7.app.AlertDialog alert11 = builder1.create();
alert11.setCancelable(false);
alert11.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
// error on line below
alert11.show();
}
}
}
}
}
が、私はこのために、インターネットを検索し、思いつきましたthisはアクティビティを作成し、その中にAlertDialogコードを行うことを示唆していますが、ユーザがOK
をクリックしてそのコードをService
で検索したときに何らかの作業をしていて、別のアクティビティ。
どうすればいいですか?
あなたの活動にはどのようなテーマが使用されていますか?あなたはツールバーを使用していますか? – Diekrul
このアクティビティの@Diekrul: 'MainActivity.class'?または放送受信機はどこですか?なぜなら、この放送受信機はサービスにあり、その質問で言われたような活動ではないからです。 –