0

在我的应用程序中,我需要一个服务才能运行。在这个假设下,我将服务设置为前台服务。我的问题是,例如在 24 小时或更长时间的服务停用后,服务没有反应。我可以在运行服务中看到我的服务,但服务的广播接收器不起作用,计划的计时器任务不会调用自己等等。

我将不胜感激任何想法可能是这种行为的原因。谢谢你。

4

2 回答 2

0

发出警报 Mabger,它会在每 2 小时后唤醒,看看你的服务是否正在运行,如果没有,它会启动服务

 alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), GeneralConstants.MAIN_SERVICE_CHECKING_TIME, pendingIntent);


if (!isServiceIsRunning(context)) {
                context.startService(new Intent(context, MainServiceAlwaysActive.class));
            }
public static boolean isServiceIsRunning(Context context) {

        // Activity manager to refer the activity/process running in system
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

        // Loop to search
        for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {

            // Basic matching
            if ("com.signals.service".equals(service.service.getClassName())) {

                return true;
            }
        }
        return false;
    }
于 2013-01-26T11:15:17.730 回答
0

经过一番调查,我得出结论,它可能是 SERVICE 的大小。服务增长到 16 Mb,然后服务停止反应。

于 2013-02-26T17:20:36.553 回答