2
即使应用程序关闭,我的任务也是运行服务。即使应用程序关闭,也运行服务
我的服务类:
public class MyService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
AudioManager am;
am= (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
if(am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL)
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
else
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Minute minute = new Minute();
Calendar cal = Calendar.getInstance();
AlarmManager alarms ;
Intent activate = new Intent(this, MyService.class);
PendingIntent alarmIntent = PendingIntent.getService(this, 0, activate, 0);
alarms = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
cal.set(Calendar.HOUR_OF_DAY, 00);
cal.set(Calendar.MINUTE, minute.minute);
cal.set(Calendar.SECOND, 00);
alarms.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), alarmIntent);
Toast.makeText(this, "checkOnStart", Toast.LENGTH_LONG).show();
return Service.START_STICKY;
}
}
在我的活动:
Intent activate = new Intent(this, MyService.class);
startService(activate);
但是,当我杀死程式的服务关闭,我应该怎么做,以保持服务上运行的应用程序被杀害后, ?
这是一个Android应用程序 – artyom
你有没有找到任何解决办法?我有同样的问题 –