相关疑难解决方法(0)

即使在强制停止后,Google日历或Instagram如何使他们的应用程序始终正常运行

看起来强制停止会阻止应用程序运行,它甚至会禁用所有应用程序的警报.然而,我发现Google日历中的通知即使在强制停止后仍然显示正常,我一直看到Instagram应用程序运行,即使我杀了它,它只是自动重启,它再一次在那里.

那么,什么是让应用程序不断运行的方法?我正在使用提醒进行应用,并且需要在特定时间显示通知,无论之前的应用是如何关闭的.

java android alarmmanager android-service

18
推荐指数
1
解决办法
620
查看次数

谁杀了我的服务?

我已经阅读了关于这个主题的每个Stackoverflow答案,但它们都没有奏效.

目标:始终保持我的服务全天候运行

问题:每当我的设备处于睡眠模式一小时或更长时间时,服务就会被终止


我试图解决它:

  • 返回START_STICKYonStartCommand()使用startForeground()

        public int onStartCommand(Intent intent, int flags, int startId) {
    
            notification = makeStickyNotification(); //I've simplified the irrelevant code, obviously this would be a real notification I build
    
            startForeground(1234, notification);
            return START_STICKY;
            }
    
    Run Code Online (Sandbox Code Playgroud)

这样工作正常,它甚至可以在设备内存不足时重新启动我的服务,但这还不足以解决我的设备暂停一段时间后出现的问题.

  • onCreate()我的Activity和onStartCommand()我的服务中使用Alarm Manager 来调用调用我的服务的广播接收器

            Intent ll24 = new Intent(this, AlarmReceiver.class);
    
            PendingIntent recurringLl24 = PendingIntent.getBroadcast(this, 0, ll24, PendingIntent.FLAG_CANCEL_CURRENT);
    
            AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    
            alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000*60, recurringLl24); // Every minute
    
    Run Code Online (Sandbox Code Playgroud)

这有助于保持我的服务活跃,但同样,不能解决我的问题

testing algorithm service android adb

7
推荐指数
2
解决办法
1428
查看次数