开机自启时如何安排任务调度

3

我已经为BOOT_COMPLETED操作编写了下一个广播接收器

public class FineWeatherBootStarter extends BroadcastReceiver {
PendingIntent pendingIntent = null;

public void onReceive(Context context, Intent intent) {

    long firstTime = System.currentTimeMillis();
    Intent serviceIntent = new Intent(FineWeather.ACTION_REFRESH);
    intent.setType(Weather.CONTENT_TYPE);
    pendingIntent = PendingIntent.getService(context, 0,serviceIntent, 0);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC,
                    firstTime, 30*1000, pendingIntent);
    Toast.makeText(context, "STARTED!!!!!!!!!", 5000).show();
}

在启动设备上我能看到"STARTED!!!!!!!!!"的消息,但我的服务似乎每30秒钟没有被启动。

问题可能出在哪里呢?


你解决了这个问题吗?我也遇到了同样的问题。 - suraj jain
1个回答

1

尝试更改您的清单文件

<receiver android:name="MyBootReceiver" android:process=":hascode_process">
        <intent-filter >
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接