android - Stopping a repeating alarm from a BroadcastReceiver - is it possible? -



android - Stopping a repeating alarm from a BroadcastReceiver - is it possible? -

i have alarmmanager sets repeating alarm purpose of periodically querying server.

private alarmmanager alarmmanager; private pendingintent pendingintent; alarmmanager = (alarmmanager) getapplicationcontext().getsystemservice(context.alarm_service); intent photosintent = new intent(this,alarmreceiver.class); //startservice(photosintent); pendingintent = pendingintent.getbroadcast(getapplicationcontext(),0,photosintent,0); alarmmanager.setrepeating(alarmmanager.elapsed_realtime, systemclock.elapsedrealtime(), 10000, pendingintent);

and start intentservice within alarmreceiver's onreceive() method. alarmreceiver broadcastreceiver. here onreceive() method:

@override public void onreceive(context context, intent intent) { intent photosintent = new intent(context,jsonphotosparser.class); context.startservice(photosintent); }

now, crazy want do, not practical. there way can stop alarmmanager within broadcastreceiver. can think of practical scenario such action required. querying status of network connection using connectivitymanager , if connection exists start intentservice queries server (which current scenario). if network status returns false, stop repeating alarm set alarmmanager.

is possible within broadcastreceiver ? understand alarmmanager can removed using cancel(pendingintent operation). how create pendingintent within broadcastreceiver ?

any help on appreciated. android noob.

refer link :

alarmmanager.cancel (pendingintent operation)

http://developer.android.com/reference/android/app/alarmmanager.html#cancel%28android.app.pendingintent%29

android android-alarms android-broadcast

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -