Android AlarmManagers lose all registered registered alarms when the phone loses power.
I use the following broadcast receiver to start when android loads:
public class AlarmBootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { Cursor alarmCursor = MainActivity.dbHelper.loadAlarms(); // Iterate through every stored alarm and set those alarms. // .... alarmCursor.close(); } } }
When the onReceive broadcast receiver starts at system startup, what context parameter is provided to the method? I need to know the context because I need the context to cancel the alarms set in this context.
I assume that calling MainActivity.dbHelper.loadAlarms () is unsafe because MainActivity is not initialized when the system boots. Or is it safe because dbhelper and loadAlarms () are all initialized and declared static?
onReceive , ? , , .
onReceive
Context onReceive(). . .
Context
onReceive()
, PendingIntent, Context, . Context, .
PendingIntent
MainActivity.dbHelper.loadAlarms() MainActivity . , dbhelper loadAlarms() static?
static
dbHelper static ( onCreate()), . , , - , , Activity . , Activity static. .
dbHelper
onCreate()
Activity
, Context BroadcastReceiver ( ApplicationContext), : 1) DBHelper, Activity. Singleton . 2) AlarmManager Service. , onReceive() Alarms
ApplicationContext
AlarmManager
Service
Source: https://habr.com/ru/post/1664807/More articles:String.init (contentsOfFile :) for Linux? - stringSynthesize over 1,500 characters with AWS Polly? - amazon-web-servicesApplying hasManyThrough to a deeper relationship - phpRemote HasManyThrough - phpRails cache ActiveRecord result - ruby | fooobar.comUsing * ngFor to create a series of switches for angular2 using the materialize-css framework - angularlaravel queue with multiple databases - phpNoClassDefFoundError with sbt and scala.swing - classpathAdding metadata to an Html5 file upload - javascriptполучить имя изображения при загрузке - htmlAll Articles