我的应用程序需要向用户提供警报,无论用户当时身在何处。此外,用户需要能够单击警报以返回到我的应用程序,该应用程序将执行一项功能。
我不能使用Toast,因为据我所知你无法点击Toast。我正在尝试使用自定义视图启动 PopupWindow。但是,当我尝试显示 PopupWindow 时,出现以下错误:
02-21 01:07:41.481: E/AndroidRuntime(1707): android.view.WindowManager$BadTokenException: 无法添加窗口 -- token null 无效;您的活动正在运行吗?
PopupWindow 是在 Service 的 onStart 方法中准备的,但后台运行的 AsyncTask 会更新视图并尝试启动 PopupWindow。是否可以从 AsyncTask 启动 PopupWindow?如果是这样,怎么办?
以下权限已添加到我的清单中。
使用权限 android:name="android.permission.SYSTEM_ALERT_WINDOW"
My application needs to provide an alert to the user no matter where the user is at the time. Also, the user needs to be able to click on the alert to return him to my application which will perform a function.
I can not use Toast, because you can not click a Toast to my knowledge. I am trying to launch a PopupWindow instead with a custom view. However, when I try to show the PopupWindow I get the following error:
02-21 01:07:41.481: E/AndroidRuntime(1707): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
The PopupWindow is prepared from within the onStart method of the Service but an AsyncTask running in the background updates the view and tries to launch the PopupWindow. Is it possible to launch the PopupWindow from the AsyncTask? IF so, how?
The following permission has already been added to my manifest.
uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"
发布评论
评论(1)
您可能希望使用NotificationManager来发出通知,并且当用户单击通知时,它会启动运行您的应用程序的意图。
http://developer.android.com/reference/android/app/NotificationManager.html
http://developer.android.com/guide/topics/ui/notifiers/notifications.html
You might want to use a NotificationManager instead to throw notifications and when the user clicks on the notification, it launches an intent to run your Application.
http://developer.android.com/reference/android/app/NotificationManager.html
http://developer.android.com/guide/topics/ui/notifiers/notifications.html