55768

Question:
I have read many questions like this but none of them seemed to address my problem.
The problem lies with:
AlertScreen ad = new AlertScreen(SensorListenerService.this);
in my Service class:
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;
}
...
It calls my AlertScreen class:
public class AlertScreen extends AlertDialog {
public AlertScreen(Context context) {
super(context);
}
...
What LogCat has to say:
<img alt="LocCat" class="b-lazy" data-src="https://i.stack.imgur.com/zqSFh.png" data-original="https://i.stack.imgur.com/zqSFh.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
Could anyone shed some light on the problem?
Answer1: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.
<blockquote><a href="https://stackoverflow.com/a/19269931/1725088" rel="nofollow">https://stackoverflow.com/a/19269931/1725088</a>
</blockquote>