public class MyHibernatedService extends Service{
public void onCreate() {
super.onCreate();
//declaring the intents ..
//some codes...
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, IntentServiceToBeRun, 0);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MILLISECOND, 10000);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
}
我希望我的Service
到每一天在某个时间推出的IntentService
。然而,我读过互联网上的某个地方,StackOverflow,谷歌等。那Service
不能永远活着,这是Android的工作原理。无论何时Android需要内存或使用太多内存,它都必须杀掉Service
。 什么保证我这个代码每天都会运行,并且我的Service
不会被杀死?执行从服务计划任务,并保持该服务活
编辑:
作为服务已启动或已绑定客户端的Android系统将试图保持过程托管服务各地只要:
我在Android文档注意
“客户绑定到”它们实际上意味着什么?