【发布时间】:2019-03-10 11:22:29
【问题描述】:
我有一个被调用的服务
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
getActivity().startForegroundService(new Intent(getActivity(),
Background.class));
} else {
getActivity().startService(new Intent(getActivity(), Background.class));
}
和它自己的服务
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this,"Creating Notification",Toast.LENGTH_SHORT).show();
//
initChannels(this);
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this, "default")
.setContentTitle("Zeep!?")
.setTicker("Zeep!?")
.setContentText("We're currently working in the background")
.setSmallIcon(R.mipmap.zeep_icon_b)
.setOngoing(true)
.setPriority(Notification.PRIORITY_MIN)
.setContentIntent(pendingIntent)
.build();
startForeground(1337, notification);
//
return START_NOT_STICKY;
}
但是每当我启动应用程序并关闭应用程序时,它就会崩溃并导致手机软重启,我对此感到非常困惑,谢谢
【问题讨论】:
标签: android foreground-service