0
我正在设置一个设置重复闹钟的应用程序。当其他应用程序正在运行时AlarmManager时间间隔发生变化
例如,它应该每2分钟运行一次我的服务。 当myApplication活动运行时,它可以很好地工作,但是当其他应用程序在前台运行时,间隔时间为5分钟!
我在前台开始的另一项服务中运行此代码。
我不知道为什么会发生这种情况。
public class Serv1 extends Service{
public static Intent intentServ2 = new Intent(G.context,Serv2.class);
public static PendingIntent pendingIntend=PendingIntent.getService(G.context,0,intentServ2,0);
public static AlarmManager alarmManager;
public int onStartCommand(Intent intent, int flags, int startId) {
alarmManager =(AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis()+(2*1000),120*1000,pendingIntend);
Intent notificationIntent = new Intent(this, Serv1.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 0,
notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Serive1")
.setContentText("Service is working...")
.setContentIntent(pendingIntent).build();
startForeground(254698, notification);
return Service.START_STICKY;
}
你在运行什么android版本? –
lollipop api 22 – Mostafa