我有一个在设备启动时运行的接收器和服务,但是假设用户从不关闭他的设备,我应该如何处理?
如何从我的接收器/服务中使用警报管理器安排状态栏通知?
package it.bloomp.service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class EventsNotificationService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
System.out.println("Service created.");
}
@Override
public void onDestroy() {
super.onDestroy();
System.out.println("Service destroyed.");
}
@Override
public void onStart(Intent intent, int startId) {
super.onCreate();
System.out.println("Service started.");
}
}
...
package it.bloomp.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class EventsNotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, EventsNotificationService.class);
context.startService(serviceIntent);
}
}
}