网站推广在线,滑雪网站的建设,网站如何做注册类 cpa,建筑工程公司名字大全集我已经阅读了一些与这个问题相关的答案,它们似乎都是一样的#xff1a;“使用START_STICKY运行您的服务”“在前台运行您的服务”“使用startService运行您的服务,不要绑定它”我正在做所有这些事情,我的服务STILL关闭并在每次关闭活动时重新启动.这不是IntentService.我也没有…我已经阅读了一些与这个问题相关的答案,它们似乎都是一样的“使用START_STICKY运行您的服务”“在前台运行您的服务”“使用startService运行您的服务,不要绑定它”我正在做所有这些事情,我的服务STILL关闭并在每次关闭活动时重新启动.这不是IntentService.我也没有在onClick处理程序中调用stopSelf或stopService.请向下滚动到我的更新 – 此行为已被确认为Android操作系统中的错误,我已将其报告给谷歌. Click here to view the report.从MainActivity启动我的服务svcIntent new Intent(getBaseContext(), MyService.class);startService(svcIntent);在我的onStartCommand中// Enter foreground stateString title Service has been started...;String subject Service is running...;String body Monitoring your battery usage.;Notification notification new Notification(R.drawable.theicon, title,System.currentTimeMillis());if (prefs.getBoolean(notificationSounds, true))notification.defaults | Notification.DEFAULT_SOUND;elsenotification.sound null;Intent notificationIntent new Intent(this, MainActivity.class);PendingIntent pendIntent PendingIntent.getActivity(this, 0, notificationIntent, 0);notification.setLatestEventInfo(this, subject, body, pendIntent);startForeground(1500, notification);在我的onStartCommand结束时...// Release WakeLockwl.release();return START_STICKY;UPDATE我想出了什么导致它但我不知道如何解决它.在我的服务中,我还使用服务中的AlarmManager在指定的时间内设置对服务的函数调用.// Alarm manager setup for MyServiceAlarmManager AM (AlarmManager) getSystemService(Context.ALARM_SERVICE);svcIntent1 new Intent(this, AlarmReceiver.class);prefs.edit().putInt(initialBatt, initialBatt).apply();svcIntent1.setAction(com.myApp.servicealarm);pendingIntent PendingIntent.getBroadcast(this, 93, svcIntent1, PendingIntent.FLAG_UPDATE_CURRENT);// Set the alarmAM.set(AlarmManager.RTC_WAKEUP, timeNow waitTime, pendingIntent);我注意到如果我不注释AM.set调用来设置警报,即使有一个EMPTY onReceive,我的服务在闹钟响起时被杀死,在我最近的应用程序中刷掉我的应用程序之后.如果我注释掉设置的警报调用,那么在关闭我的应用程序后,服务永远不会被杀死并继续运行.有没有搞错我的算法功能需要这个警报这很奇怪.一旦闹钟响起,我的调试消息就不会打印,我的服务会重新启动.但第二次,在服务重新启动后,调试消息会打印并且程序成功执行.我已经尝试了这个,它仍然发生在普通的广播接收器上.我还将我的代码剥离到我的服务和广播接收器的设置警报调用,同样的事情发生,所以这不是我的算法.显然,如果您有一个设置闹钟的前台服务,当闹钟响起时,您的服务将重新启动.闭幕这种行为似乎是由Android操作系统中的一个错误引起的,所以我不希望得到答案.如果你想自己看看这个bug,click here.我提供了一个你可以编译并重现问题的项目.