无法添加窗口-令牌null不适用于Service中的应用程序 [英] Unable to add window -- token null is not for an application from Service

查看:87
本文介绍了无法添加窗口-令牌null不适用于Service中的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过很多这样的问题,但似乎没有一个能解决我的问题.

I have read many questions like this but none of them seemed to address my problem.

问题在于:

 AlertScreen ad = new AlertScreen(SensorListenerService.this);

在我的服务班级:

public class SensorListener extends Service implements SensorEventListener {

public int onStartCommand(Intent intent, int flags, int startId) {
    startForeground(Process.myPid(), new Notification());

    AlertScreen ad = new AlertScreen(SensorListener.this); //problem
    ad.show();
    
    return START_STICKY;
}
...

它调用我的AlertScreen类:

It calls my AlertScreen class:

public class AlertScreen extends AlertDialog {

public AlertScreen(Context context) {
    super(context);
}
...

LogCat怎么说:

What LogCat has to say:

有人可以阐明这个问题吗?

Could anyone shed some light on the problem?

推荐答案

您无法从Service上下文显示对话框.

You cannot show Dialogs from a Service context.

我建议您打开一个实际显示对话框的活动,或查看此答案以了解如何显示系统警报.

I suggest you to open an Activity that actually shows the dialog, or take a look at this answer to learn how to show system alerts.

https://stackoverflow.com/a/19269931/1725088

这篇关于无法添加窗口-令牌null不适用于Service中的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆