打死我有應用,其主要功能取決於報警,但報警有時候有時候解僱不,我紅一下其表示,由於系統殺死的火警之前您的應用程序,我怎麼能保證報警即使應用殺害,後在這裏要火,我怎麼設置報警如何確保火警即使應用程序通過系統
public static void setEndAlarm(){
AlarmManager alarmManager = (AlarmManager) MyApplication.getContext().getSystemService(Context.ALARM_SERVICE);
Calendar time = Calendar.getInstance();
time.setTimeInMillis(System.currentTimeMillis());
time.set(Calendar.HOUR_OF_DAY, SharedPrefUtils.getEndHour(MyApplication.getContext()));
time.set(Calendar.MINUTE, SharedPrefUtils.getEndMin(MyApplication.getContext()));
time.set(Calendar.SECOND, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), endPendingIntent(MyApplication.getContext()));
}
private static PendingIntent endPendingIntent(Context context){
Intent intent = new Intent(context, ClsEndBroadcastReciever.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 02, intent, PendingIntent.FLAG_ONE_SHOT);
return pendingIntent;
}
和獲得方面是這樣的:
public class MyApplication extends Application {
private static Context mContext;
@Override
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
}
public static Context getContext() {
return mContext;
}
}
廣播接收器:
public class ClsEndBroadcastReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
FirebaseJobDispatcher dispatcher = new
FirebaseJobDispatcher(new GooglePlayDriver(context));
dispatcher.cancel("notification");
Toast.makeText(context, "End Time", Toast.LENGTH_SHORT).show();
}
}
我覺得服務也殺死了,是真的 – blackHawk
是在像OPPP一些設備,體內和許多類似的Android定製的設備,如果你從任務欄中刪除應用程序(滑動清除),然後該應用程序將強制停止,使您的所有服務被殺死。 –
所以,我怎麼能保證我的應用程序 – blackHawk