Java 无法关闭间隔服务
即使关闭应用程序,该服务仍处于活动状态 启动服务: @凌驾 受保护的void onCreateBundle savedInstanceState{ super.onCreatesavedInstanceState; setContentViewR.layout.activity\u促销; Toolbar Toolbar=Toolbar findViewByIdR.id.Toolbar; 设置支持操作工具栏; //服务 Calendar cal=Calendar.getInstance; cal.addCalendar.SECOND,10; Intent intent1=新Intentthis,PositionService.class; PendingEvent pintent=PendingEvent.getServicethis,0,intent1,0; AlarmManager alarm=AlarmManager getSystemServiceContext.alarm\u服务; alarm.setRepeatingAlarmManager.RTC_WAKEUP,cal.getTimeInMillis,15*1000,pintent; StartServiceNewIntentGetBaseContext,PositionService.class; } 添加START\u NOT\u STICKY,这将阻止服务再次启动:Java 无法关闭间隔服务,java,android,service,Java,Android,Service,即使关闭应用程序,该服务仍处于活动状态 启动服务: @凌驾 受保护的void onCreateBundle savedInstanceState{ super.onCreatesavedInstanceState; setContentViewR.layout.activity\u促销; Toolbar Toolbar=Toolbar findViewByIdR.id.Toolbar; 设置支持操作工具栏; //服务 Calendar cal=Calendar.getInstance; cal.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Service Running", Toast.LENGTH_SHORT).show();
/* Uso de la clase LocationManager para obtener la localizacion del GPS */
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Localizacion Local = new Localizacion();
Local.setMainActivity(this);
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, (LocationListener) Local);
return START_NOT_STICKY; //here
}
问题是启动服务的警报 Intent Intent=new IntentPromotionActivity.this,PositionService.class; PendingEvent pintent=PendingEvent.getServicePromotionActivity.this,0,intent,0; AlarmManager alarm=AlarmManager getSystemServiceContext.alarm\u服务;
报警、取消提示;您的服务类别代码在哪里?即使在停止服务运行或应用程序终止后更新信息?感谢回复,该服务似乎非常积极,继续使用建议的行代码运行,是否还有其他可能性?即使在终止应用程序后,它是否仍在使用toast消息运行?是的,我的朋友,服务一直在运行