Ngày tốt, tôi đang cố gắng hiển thị hộp thoại cảnh báo sau khi khởi động lại hệ thống trong bộ thu phát sóng. Tôi đã thêm người nhận vào tệp kê khai của mình và gọi là quyền cần thiết, nhưng tôi gặp lỗi khi hiển thị hộp thoại. Hãy Làm thế nào tôi có thể thực hiện điều này một cách chính xác .. Cảm ơn bạnhiển thị hộp thoại cảnh báo trong bộ thu phát sau khi khởi động lại hệ thống
mã của tôi:
public void onReceive(final Context context, Intent intent) {
Log.d(TAG, "received boot completed broadcast receiver... starting settings");
String settings = context.getResources().getString(R.string.restart_setting);
String yes = context.getResources().getString(R.string.Settings);
String no = context.getResources().getString(R.string.Cancel);
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(settings)
.setCancelable(false)
.setPositiveButton(yes, new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id)
Intent config = new Intent(context, WeatherConfigure.class)
context.startActivity(config);
}
})
.setNegativeButton(no, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
đang nhận được lỗi đăng nhập này:
01-07 01:42:01.559: ERROR/AndroidRuntime(2004): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
01-07 01:42:01.559: ERROR/AndroidRuntime(2004): at android.view.ViewRoot.setView(ViewRoot.java:548)
01-07 01:42:01.559: ERROR/AndroidRuntime(2004):at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
01-07 01:42:01.559: ERROR/AndroidRuntime(2004): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-07 01:42:01.559: ERROR/AndroidRuntime(2004):at android.app.Dialog.show(Dialog.java:288)
01-07 01:42:01.559: ERROR/AndroidRuntime(2004):at com.MuaaApps.MyWeatherUpdate.myWeatherBroadcastReceiver.onReceive(MyWeatherBroadcastReceiver.java:59)
01-07 01:42:01.559: ERROR/AndroidRuntime(2004): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1994)
Một thông báo Bánh mì nướng hoặc Thông báo có thể phù hợp hơn trong trường hợp này, thay vì làm nổ người dùng bằng hộp thoại cảnh báo khi điện thoại của họ bật. – cottonBallPaws
@littleFluffyKitty, vâng tôi hiểu ý bạn là gì. Tôi chỉ thử các kịch bản khác nhau để xem tôi nghĩ gì sẽ mang lại trải nghiệm người dùng tốt, nhưng tôi phải thừa nhận đề xuất thông báo bạn đã thực hiện là một lựa chọn rất hấp dẫn. không nghĩ về điều đó. Cảm ơn – irobotxxx