broadcastreceiver - Stopping alarms after the app is killed Android -



broadcastreceiver - Stopping alarms after the app is killed Android -

i have situation in application. calling service using alarm. alarm wakes every 5 min , calls service.

but may happen user might close app , allowing functionality of service work if user not using app.

to stop service there 2 ways either user comes app , presses button cancel alarm or sec way after x time want stop service i.e cancel alarm broadcast receiver.

now how can sec way ? when tried reference of alarmmanager giving me error of null pointer. (i accessing alarm manager broadcast receiver)

can give me suggestion on how cancel repeating alarms outside activity context ?

thanks :)

you can stop service context.stopservice(new intent(context, yourservice.class))

also in order cancel alarm can this

intent intent = new intent(this, yourclass.class); pendingintent pendingintent = pendingintent.getbroadcast(getapplicationcontext(), 1253, intent, pendingintent.flag_update_current| intent.fill_in_data); alarmmanager alarmmanager = (alarmmanager) getsystemservice(alarm_service); alarmmanager.cancel(pendingintent);

i hope might help you

android broadcastreceiver alarmmanager android-pendingintent

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -