无法添加窗口 - 令牌null不适用于Service的应用程序

C_B*_*C_B 3 android android-alertdialog

我读过很多像这样的问题,但似乎都没有解决我的问题.

问题在于:

 AlertScreen ad = new AlertScreen(SensorListenerService.this);
Run Code Online (Sandbox Code Playgroud)

在我的服务类中:

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;
}
...
Run Code Online (Sandbox Code Playgroud)

它调用我的AlertScreen类:

public class AlertScreen extends AlertDialog {

public AlertScreen(Context context) {
    super(context);
}
...
Run Code Online (Sandbox Code Playgroud)

LogCat有什么要说的:

LocCat

谁能解释一下这个问题呢?

kup*_*sef 7

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

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

/sf/answers/1348895201/