tag:blogger.com,1999:blog-32870248847068299.post4467054776181993950..comments2024-03-27T09:02:13.262-07:00Comments on Android Tutorials for Beginners: Scheduling Task Using Alarm Managerkamlesh Yadavhttp://www.blogger.com/profile/00613228710241117815noreply@blogger.comBlogger22125tag:blogger.com,1999:blog-32870248847068299.post-90819121738063724242020-10-20T07:55:22.302-07:002020-10-20T07:55:22.302-07:00Nice blog, I will keep visiting this blog very oft...Nice blog, I will keep visiting this blog very often. <a href="https://ppthietbidien24h.com/he-thong-bao-chay-notifier-honeywell/" rel="nofollow">thiết bị báo cháy</a>Azcustomcarshttps://www.blogger.com/profile/00413580583294477394noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-76310040174146515552019-07-02T03:05:04.248-07:002019-07-02T03:05:04.248-07:00Nice blog, I will keep visiting this blog very oft...Nice blog, I will keep visiting this blog very often. <a href="https://phongchayphucthanh.com/bao-chay-hochiki/" rel="nofollow">thiết bị báo cháy hochiki</a>josphenehttps://www.blogger.com/profile/06136380173422519251noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-82369231916468810612019-04-17T19:00:15.702-07:002019-04-17T19:00:15.702-07:00Howdy, There's no doubt that your web site
co...Howdy, There's no doubt that your web site <br />could possibly be having web browser compatibility problems.<br />Whenever I look at your site in Safari, it looks fine however, when opening in IE, it has <br />some overlapping issues. I just wanted to give you a <br />quick heads up! Other than that, excellent website!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-46200879016218114792017-01-26T23:08:34.055-08:002017-01-26T23:08:34.055-08:00Best answer so far! Was finding solution for 4 day...Best answer so far! Was finding solution for 4 days now!RUTURAJ R. Ravalhttps://www.blogger.com/profile/06940872804217370584noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-49454981849624393692016-10-20T03:56:07.135-07:002016-10-20T03:56:07.135-07:00Hi, how can a I link my user preferred date and ti...Hi, how can a I link my user preferred date and time using date and time picker to the alarm system.Anonymoushttps://www.blogger.com/profile/10428751711162719218noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-74307849933098985502016-05-30T16:29:36.558-07:002016-05-30T16:29:36.558-07:00To make this Alarm *REPEAT* at the time intervals ...To make this Alarm *REPEAT* at the time intervals you want, you just need to change some code in *MainActivity.Java*<br />Here we go ...<br /><br />(1) Look for this line in the *MainActivity.java*<br /><br />Long time = new GregorianCalendar().getTimeInMillis() + 24*60*60*1000;<br /><br />(Hey be careful, this 24*60*60*1000 in the above line is for *ONE DAY TIME* this alarm will set off after you've clicked the button in the app.<br />So let's change it into shorter time span for testing in the first place.<br />How about we set it into about 15 seconds?<br /><br />OK, 15 seconds in *Milliseconds" is 15000. (Just multiply it by 1000 ) <br /><br />So re-write the above code with like this. (And delete the old line of code after this)<br />We get new one.<br /><br />Long time = new GregorianCalendar().getTimeInMillis() + 15000; // Remember 15 seconds (for testing)<br /><br />(2) Add this line below it.<br /><br />int time2 = 20000; // That is 20 seconds * 1000 <br /><br />OK, we now got two *time* varibles! <br />The first original "time" is the time when our alarn will set off (after button click of course!)<br />The newly-added "time2" is the time interval that our alarm will take to repeat itself AGAIN! (after 20 seconds in our case)<br /><br />(3) Finally change the whole line before the last line into this one.<br /><br />alarmManager.setRepeating((AlarmManager.RTC_WAKEUP),time, time2,PendingIntent.getBroadcast(this,1,intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));<br /> <br />Here we just made two changes in the codes above!<br />The first one is: We changed "set ..." into "setRepeating((...."<br />And the second one is: We just added our new variable "time2" after the original "time" varible.<br /><br />That is it. Rebuild the app with these changes and then you get an alarm REPEATING EVERY "time2" time!! :)<br /><br />For further clarity, here below is the snippets of code with the changes we just made:<br /><br />///////////////////<br /><br />Long time = new GregorianCalendar().getTimeInMillis() + 15000; // Alarm will set off after 15 seconds<br />int time2 = 20 * 1000; // Repeat for *EVERY* 20 second<br /><br /> // create an Intent and set the class which will execute when Alarm triggers, here we have <br /> // given AlarmReciever in the Intent, the onRecieve() method of this class will execute when <br /> // alarm triggers and <br /> //we will write the code to send SMS inside onRecieve() method pf Alarmreciever class<br /> <br /> Intent intentAlarm = new Intent(this, AlarmReciever.class);<br /> <br /> // create the object<br /> <br /> AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); <br /> <br /><br /> //set the alarm for particular time<br /><br /> alarmManager.setRepeating((AlarmManager.RTC_WAKEUP),time, time2,PendingIntent.getBroadcast(this,1,intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));<br /> Toast.makeText(this, "Alarm Scheduled for Tommrrow", Toast.LENGTH_LONG).show();<br /> <br />///////////////////<br /> <br />By the way, you can comment out the code that actually sends SMS in the *AlarmReciever.java* file if you don't want SMS being sent during testing.<br />I hope this helps. Good luck! :)Anonymoushttps://www.blogger.com/profile/01085042811638443757noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-79087508717535134472016-05-20T04:32:33.345-07:002016-05-20T04:32:33.345-07:00What if i want to run my code multiple time withou...What if i want to run my code multiple time without any pattern,like 9am,10pm then again tomorrow at same time how to do that with one AlarmManager object?Tech Sunlighthttps://www.blogger.com/profile/14567263434563211998noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-55249982854276029592015-10-15T06:37:30.973-07:002015-10-15T06:37:30.973-07:00Never mind it works like a charm!!! Love you!Never mind it works like a charm!!! Love you!cBeasthttps://www.blogger.com/profile/05175519123983374418noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-82197060640816663862015-10-15T06:26:55.437-07:002015-10-15T06:26:55.437-07:00Nice one, but what happens, if the app stop workin...Nice one, but what happens, if the app stop working on the background?cBeasthttps://www.blogger.com/profile/05175519123983374418noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-18026731504459918282015-02-02T11:14:21.029-08:002015-02-02T11:14:21.029-08:00I tried following your tutorial, however it refuse...I tried following your tutorial, however it refuses to work unless I make the AlarmReciever class static, which leads to a bunch of other problems for me :). How did you manage to avoid that? Thanks!!!Anonymoushttps://www.blogger.com/profile/14078466862944251956noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-61926902101529734492015-02-02T11:13:25.907-08:002015-02-02T11:13:25.907-08:00I tried following your tutorial, however it refuse...I tried following your tutorial, however it refuses to work unless I make the AlarmReciever class static, which leads to a bunch of other problems for me :). How did you manage to avoid that? Thanks!!!Anonymoushttps://www.blogger.com/profile/14078466862944251956noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-57065035061669496352015-01-24T22:44:04.787-08:002015-01-24T22:44:04.787-08:00Wah!!! Thank you so much for this... This is the ...Wah!!! Thank you so much for this... This is the best and most simplest example of AlarmManager I could find on the net.... <br />Kudos...!!!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-23399399595604936432014-03-19T05:56:18.732-07:002014-03-19T05:56:18.732-07:00Thank you very much. We were trying to make a simi...Thank you very much. We were trying to make a similar app, but were not able to schedule the events. Now , thanks to you, we know :) Thanks again...Anonymoushttps://www.blogger.com/profile/14827270726970716408noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-52241204150484649112014-02-11T08:05:56.778-08:002014-02-11T08:05:56.778-08:00You are a LIFE-SAVER!
Oh man been looking around ...You are a LIFE-SAVER!<br /><br />Oh man been looking around for an example on how to trigger an event in future and all examples I came across are so unnecessarily complicated and convoluted! <br /><br />Your code rocks! I love it!<br />Thanks a lot for sharing this!Unknownhttps://www.blogger.com/profile/07531090342381181243noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-40462801852320714632013-12-22T02:56:24.061-08:002013-12-22T02:56:24.061-08:00Admin I removed all the errors, I was missing getT...Admin I removed all the errors, I was missing getTimeInMillis().<br /><br />Bt the code is still not getting invoked @ 12:00:00.....pls guide.<br /><br />Or atleast tell where can i paste my code, such that u can give a chk.Anonymoushttps://www.blogger.com/profile/01995072699322380965noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-64957498535215882032013-12-21T22:21:51.842-08:002013-12-21T22:21:51.842-08:00@Kamlesh: Dear Admin, I tried GregorianCalendar gc...@Kamlesh: Dear Admin, I tried GregorianCalendar gc=new GregorianCalendar(year, month, day, hour, minute, second);<br /><br />Then the error comes at AlarmManger.set(), it says to change thr type of gc to Long. (i.e. gc cannot be GregorianCalendar).<br /><br />So if i do change the above mentioned thing, then gc cannot be Long.<br /><br />I cant even try casting here....<br /><br />So pls give a solution .....<br />Thanks in Advance.Anonymoushttps://www.blogger.com/profile/01995072699322380965noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-55788688529189983462013-12-18T05:09:11.422-08:002013-12-18T05:09:11.422-08:00Dear Admin, Nice Tutorial.
But could u pls guide ...Dear Admin, Nice Tutorial.<br /><br />But could u pls guide me that how to execute this code everyDay.....pls.<br /><br />i.e. a msg shud go everyday. Dynamically.<br /><br />I need this code. Thanks in advance.Anonymoushttps://www.blogger.com/profile/01995072699322380965noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-34990376144531732942013-12-18T05:04:46.376-08:002013-12-18T05:04:46.376-08:00Hi Admin....Nice Tutorial. Thanks.
But i have a d...Hi Admin....Nice Tutorial. Thanks.<br /><br />But i have a doubt. Your code work awesome once.<br /><br />What if i want to do it again & again.<br /><br />I mean u did it for 1 day. What if i want to do it EveryDay that too Dynamically....<br /><br />Please Reply.....Thanks in Advance.Anonymoushttps://www.blogger.com/profile/01995072699322380965noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-6133438693619920662013-11-10T23:45:15.931-08:002013-11-10T23:45:15.931-08:00Nice tutorial dude.... It helps me lot..Nice tutorial dude.... It helps me lot..Anonymoushttps://www.blogger.com/profile/07197502549038410466noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-87999491388515365992013-09-14T05:53:55.648-07:002013-09-14T05:53:55.648-07:00i am new to Android and working on a app which tak...i am new to Android and working on a app which take a int value from "if statements".Now the 1st prob is m not getting how to send value to broadcastReceiver and second is int value changes on "if " condition, now how can i send the value that is stored according to the conditionAnonymoushttps://www.blogger.com/profile/14600465236502201493noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-46730201012433858172013-07-09T01:01:40.637-07:002013-07-09T01:01:40.637-07:00Hi Rekha
With following code you will get the curr...Hi Rekha<br />With following code you will get the current time in Milseconds.<br /> Long time = new GregorianCalendar().getTimeInMillis();<br />You can some value like 24*60*60*1000 to schedule the alarm for tommorow.<br /><br />1: The other way is Use time picker and date picker and schedule the alarm at User Selected date or Time.<br /><br />2: GregorianCalendar gc=new GregorianCalendar(year, month, day, hour, minute, second); you can pass the arguments here. <br />Like schedule at 10th july 2013, 12:00:00<br />GregorianCalendar gc=new GregorianCalendar(2013, 6, 10, 12, 00, 00);<br /><br />You can also set the time as <br /> gc.set(Calendar.DAY_OF_MONTH, 10);<br /> gc.set(Calendar.YEAR, 2013); and so on<br /><br /><br />Let me know any more concern.kamlesh Yadavhttps://www.blogger.com/profile/00613228710241117815noreply@blogger.comtag:blogger.com,1999:blog-32870248847068299.post-22910144900643609012013-07-08T21:44:50.963-07:002013-07-08T21:44:50.963-07:00Hi kamlesh..
what should we use if we want to sche...Hi kamlesh..<br />what should we use if we want to schedule the alarm at specific date and time..for eg. alarm trigger on 10th july 2013, 12:00:00rekhahttps://www.blogger.com/profile/04384626705030983035noreply@blogger.com