How to prompt to user an alert dialog but not when my app is forground?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 06:29:57

问题


i want to show the user an alert dialog message, that he can choose yes/no but i want to do that automatical even and mainly when my app is not forground,

like clock alarm, that can jump up to screen in any situation (even if user in call)..

how to do that? i succeed to do alert.. but its came up just when my app is forground :/ using this guide: http://www.androidhive.info/2011/09/how-to-show-alert-dialog-in-android/

please help me, thank's.


回答1:


You can't, AFAIK, a Dialog needs an Activity. An option you have that may satisfy your needs is to create an Activity with a Dialog Theme and call this in a Receiver. All you need to do to make it look like an AlertDialog is to add

android:theme="@android:style/Theme.Dialog"

to the <activity> tag in the manifest.

BroadcastReceiver



来源:https://stackoverflow.com/questions/18240413/how-to-prompt-to-user-an-alert-dialog-but-not-when-my-app-is-forground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!