第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

系統(tǒng)重新啟動后,在廣播接收器中顯示警報對話框

系統(tǒng)重新啟動后,在廣播接收器中顯示警報對話框

繁華開滿天機 2019-10-29 14:50:25
美好的一天,在廣播接收機中,系統(tǒng)重新啟動后,我試圖顯示一個警報對話框。我已經(jīng)在清單中添加了接收者并調(diào)用了所需的權(quán)限,但是在顯示對話框時出現(xiàn)錯誤。請問我該如何正確實施呢?我的代碼: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();    }正在收到此日志錯誤: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 application01-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)
查看完整描述

3 回答

?
蕪湖不蕪

TA貢獻(xiàn)1796條經(jīng)驗 獲得超7個贊

這是有關(guān)如何執(zhí)行此操作的帖子。您可以從此處獲取源代碼。

您不能直接從廣播接收器顯示對話框。您必須使用Activity。另外,為了接收ACTION_BOOT_COMPLETED您的活動,必須首先由用戶或其他應(yīng)用程序顯式啟動(有關(guān)更多信息,Google應(yīng)用程序處于停止?fàn)顟B(tài))。

基本上,要實現(xiàn)所需的功能,您需要執(zhí)行以下操作:

  1. 創(chuàng)建顯示對話框的透明活動。

  2. 創(chuàng)建BroadcastReceiver將接收ACTION_BOOT_COMPLETED并開始您的活動。

  3. 在清單中注冊您的廣播接收器并獲得適當(dāng)?shù)脑S可。

此外,此問題提供有關(guān)如何創(chuàng)建透明活動的更多信息。


查看完整回答
反對 回復(fù) 2019-10-29
  • 3 回答
  • 0 關(guān)注
  • 491 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號