如果我在一个活动中,我会使用下面的代码调用服务b:
String start = "start";
Intent i = new Intent(QScheduleActivity.this, UploadService.class);
i.putExtra("start", start);
startService(i)一旦我进入此服务,如果需要,如何从服务中调用该服务?
在else中,我尝试像这样调用该服务:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 30);
String start = "start";
Intent i = new Intent(UploadService.this, UploadService.class);
i.putExtra("start", start);
PendingIntent sender = PendingIntent.getBroadcast(this, 192837, i, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); 发布于 2011-01-20 21:10:05
在else中的
我尝试像这样调用服务:
您请求的是getBroadcast() PendingIntent。如果您的目标是让报警呼叫startService(),则应该使用getService() PendingIntent。
发布于 2011-01-20 21:00:16
看一下AlarmManager类。我认为它提供了您需要的功能,尽管可能不是以您所描述的方式。
从文档中:
此类提供对系统报警服务的访问。这些允许您安排您的应用程序在将来的某个时候运行。当警报响起时,系统将广播已为其注册的Intent,如果目标应用程序尚未运行,则会自动启动目标应用程序。设备处于休眠状态时,会保留已注册的警报(如果设备在此期间关闭,还可以选择唤醒设备),但如果设备关闭并重新启动,则会将其清除。
https://stackoverflow.com/questions/4747350
复制相似问题