在BOOT_COMPLETED上调度tasl

时间:2011-08-16 11:25:58

标签: android broadcastreceiver android-service

我为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秒启动

哪里可以成为问题&

1 个答案:

答案 0 :(得分: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>