Android - Alarm doesn`t fire sometimes after long period
<p>I have a big problem with my app for serveral days now. I appologize if my english is not so native in advance. I implemented an AlarmManager to give the user of my app the option to start a certain service at any time of the current or the next day. So e.g. the user might choose to set the time for my service to tomorrow at 08:00 a.m. and then starts the service.</p>

<p>The alarm manager should now wait the calculated time from now till the chosen time (i calculated the time also manually and it is correct!) and then start the service. My problem now is that sometimes the alarmmanager is starting my service and somtimes not. It seems that if it has to wait for lets say more than 4 hours it is not working any more and my service is not called. I have set all neccessary permission otherwise it would not work at all. You can have a look at the code of the alarmmanager below:</p>

<pre><code>someIntent = new Intent();
someIntent.setAction("START_SERVICE");
AlarmManager alarams ;

alarmIntent = PendingIntent.getBroadcast(MainActivity.this, 0, someIntent, PendingIntent.FLAG_CANCEL_CURRENT);
alarams = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarams.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+delay, alarmIntent);
</code></pre>

<p>The broadcast receiver is implemented like this (and it is registered!):</p>

<pre><code>alarmReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {

                Intent myIntent = new Intent(MainActivity.this, MyService.class);
                startService(myIntent);
            }
        };
</code></pre>

<p>As I told you, if it is not working it stops before starting the service. I would really appreciate if you could help me!!!!!!!!!!!!!!!!!!</p>

<p>Thanks a lot in advance for your time!</p>

<p>eMu</p>

<p>EDIT:
I have an idea. I read something in this thread: <a href="http://stackoverflow.com/questions/9138597/android-long-running-service-with-alarm-manager-and-inner-broadcast-receiver">Android long running service with alarm manager and inner broadcast receiver</a></p>

<p>It might be, that my constructor for the intent "someIntent" only works for BroadcastReceivers declared in the manifest file. So in my case I should maybe use <code>someIntent = new Intent("START_SERVICE")</code> instead of <code>someIntent = new Intent(); someIntent.setAction("START_SERVICE")</code>. This effect is called tunneling - i will figure it out, if it works i will post my experience here. Thanks for the well explained answer on the mentioned thread! If you have any other ideas or the same experiences like me please let me know!
eMu</p>
