打死我有应用,其主要功能取决于报警,但报警有时候有时候解雇不,我红一下其表示,由于系统杀死的火警之前您的应用程序,我怎么能保证报警即使应用杀害,后在这里要火,我怎么设置报警如何确保火警即使应用程序通过系统
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