Wednesday, April 9, 2014

AlarmManager every two minutes to perform a task, but it is actually an integer multiple of the implementation of every 2


posts by shanebest edited 2013-09-24 23:06:23
Recently tried to implement a function, and in the state can lock screen every two minutes to start service, perform a task. google a lot of big cattle blog, did not get a satisfactory solution. I understand the system is relatively shallow, large cattle were able to look over to help.

Required to achieve AlarmManager every two minutes to perform a task, but it can actually turn off the screen test every two integer multiple execute my task. In order to monitor my program, I wrote a written log of the sdcard function, used to monitor whether the service needs work.

The key part of the code:
This part is actually an example of Sample inside, inherited an Activity, in which the realization:
 / / Activity code; setting start every two minutes, after clicking the Start Button 
long firstTime = SystemClock.elapsedRealtime ();
/ / Schedule the alarm!
AlarmManager am = (AlarmManager) getSystemService (ALARM_SERVICE);
am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP,
firstTime, 2 * 60 * 1000, mAlarmSender);


This part of the following: In the Service of the implementation, monitoring log records written in sdcard, is designed to detect whether the service task to run every two minutes.
ReadAndWrite (). WriteTxtFile () is a function of written characters I write in sdcard.
 / / Get the current time (accurate to milliseconds), the format: yyyy-mm-dd hh: mm: ss.nnn 
String currentTime = new java.sql.Timestamp (System.currentTimeMillis ()) toString ();.
new ReadAndWrite (). WriteTxtFile (
Environment.getExternalStorageDirectory ()
+ "/ MyAlarmManager.log",
currentTime
+:;
"Am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 2 * 60 * 1000, mAlarmSender) (every two minutes) start the Service again, this section is"+ (+ + Count) + "times");

startMyActivity ("com.austin.myalarmmanager",
"Com.austin.myalarmmanager.PopUpDisplay");



3, the program outputs the test results, this is my log file from Sdcard in replication, please take them to see the big minute recording interval, I now ask is how every two minutes is an integer multiple of the task, how in order to achieve my needs. Also how can we change the time needed to get the cpu wake achieve lock when not returned to the system, not to the device useless power consumption increase? Here is the test record:
 2013-09-23 02:22:18.785: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) Start Service once, The 20th is 
2013-09-23 02:24:18.788: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 21st
2013-09-23 02:25:45.717: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 22nd
2013-09-23 02:29:45.715: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
23 times for2013-09-23 02:33:45.713: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 24th
2013-09-23 02:37:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 25th
2013-09-23 02:41:45.719: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 26th
2013-09-23 02:45:45.716: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 27th
2013-09-23 02:49:45.725: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 28th
2013-09-23 02:53:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 29th
2013-09-23 02:57:45.712: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 30th
2013-09-23 03:01:45.715: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
31 times for2013-09-23 03:05:45.713: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the first 32


Omitting the middle section are recorded every 4 minutes
And from two minutes or less normal to 4 minutes, 2 minutes, when I open the screen, so the normal
 2013-09-23 07:41:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) Start Service once, The 89th is 
2013-09-23 07:43:45.71: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 90th
2013-09-23 07:45:45.713: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 91st
2013-09-23 07:47:45.713: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 92nd
2013-09-23 07:51:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
93 times for2013-09-23 08:13:45.716: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 94th
2013-09-23 08:17:45.715: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 95th
2013-09-23 08:21:45.715: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 96th
2013-09-23 08:25:45.715: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 97th
2013-09-23 08:29:45.715: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 98th
2013-09-23 08:33:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 99th
2013-09-23 08:37:45.712: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 100 th


The following paragraph is 3:00 to 4:00, I promise I did feels coding, so the screen has been turned off
 2013-09-24 03:03:45.712: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) Start Service once, The 343rd is 
2013-09-24 03:07:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
344 times for2013-09-24 03:11:45.711: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
345 times for2013-09-24 03:15:45.713: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
346 times for2013-09-24 03:19:45.71: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
347 times for2013-09-24 03:23:45.716: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 348th
2013-09-24 03:27:45.723: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
349 times for2013-09-24 03:31:45.712: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
350 times for2013-09-24 03:35:45.711: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
351 times for2013-09-24 03:39:45.769: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the Section 352
2013-09-24 03:43:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
353 times for2013-09-24 03:47:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
354 times for2013-09-24 03:51:45.715: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
355 times for2013-09-24 03:55:45.713: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
356 times for2013-09-24 03:59:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
357 times for2013-09-24 04:03:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
358 times for2013-09-24 04:07:45.719: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
359 times for2013-09-24 04:11:45.712: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 360th
2013-09-24 04:15:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
361 times for2013-09-24 04:19:45.712: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
362 times for2013-09-24 04:23:45.713: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
363 times for2013-09-24 04:27:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the 364th
2013-09-24 04:31:45.716: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
365 times for2013-09-24 04:35:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
366 times for2013-09-24 04:39:45.713: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
367 times for2013-09-24 04:43:45.773: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
368 times for2013-09-24 04:47:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
369 times for2013-09-24 04:49:45.71: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
370 times for2013-09-24 04:53:45.714: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this
371 times for2013-09-24 04:57:45.712: am.setRepeating (AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, TIME * 60 * 1000, mAlarmSender); (every two minutes) start the Service again, this time for the first 372
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
I use AlarmManager.RTC_WAKEUP mode can be set in accordance with the frequency
Reply:
Is indeed a bit strange, you have to call in a service where startMyActivity doing, the state of the timer is already circulating, no need to call again.
Reply:
reference to the second floor tcmakebest reply:
indeed a bit strange, you have to call in a service where startMyActivity doing, the timer is already circulating the state, not need to call again.
background service calls Activity, of course, is to display the contents of the screen ah.
Reply:
reference to the second floor tcmakebest reply:
indeed a bit strange, you have to call in a service where startMyActivity doing, the timer is already circulating the state, not need to call again.
This should start the Activity is another thing
Reply:
cited a floor luowenlong860502 reply:
I use AlarmManager.RTC_WAKEUP mode can be set according to the frequency
you determine the phone is not always wake up other programs? My mobile phone is another custom machines, piles of custom software running in the background, an estimated their credit, according to the frequency that mobile phones can perform the task.
Reply:
The reply was deleted administrator at 2013-09-27 09:07:30

Reply:
references, 5th Floor shanebest reply:
Quote: references to a floor luowenlong860502 reply:

I use AlarmManager.RTC_WAKEUP mode can be set according to the frequency
Are you sure the phone is not always wake up other programs? My mobile phone is another custom machines, piles of custom software running in the background, an estimated their credit, according to the frequency that mobile phones can perform the task.

Absolutely not, you can download a wakelock detector to see what the program has to wake up

No comments:

Post a Comment