AlarmReceiver works only for short time (WakeLock? / Process killed?)
<p>I have an <code>AlarmReceiver</code> with an <code>AlarmService</code> and my problem is, if I set the AlertDate about 30min away from the current time, it just does it's job and calls the <code>Alert</code>-function. But if I set it about 5hours away, it won't call the function, no matter if I do it at night (not using my phone) or at day (while my phone is in use).</p>

<p><strong>So my question is, why can't I set the AlertDate in the "far" future? Is the process killed or is there anything strange happening? And in particular: How can I fix this problem??</strong></p>

<p>Basically I have the arrangement from here: <a href="http://javapapers.com/android/android-alarm-clock-tutorial/" rel="nofollow">Android Alarm Clock Tutorial</a></p>

<p>So I just point out my main lines in the code:</p>

<p><code>Manifest</code>:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apm.smoothalert" &gt;

&lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
&lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD" /&gt;

...

&lt;application

    ...

    &lt;activity
        android:name=".main"
        android:label="@string/app_name" &gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.MAIN" /&gt;
            &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;

    &lt;service
        android:name=".AlarmService"
        android:enabled="true" /&gt;

    &lt;receiver android:name=".AlarmReceiver" /&gt;

&lt;/application&gt;
</code></pre>

<p></p>

<p><code>main</code>:</p>

<pre><code>public class main extends ActionBarActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        PowerManager powman = (PowerManager) getSystemService(POWER_SERVICE);
        PowerManager.WakeLock wakeLock = powman.newWakeLock(PowerManager.FULL_WAKE_LOCK,"MyWakelockTag");
        wakeLock.acquire();

        ...

    }

    AlarmManager alarmManager;
    private PendingIntent pendingIntent;

    private void smoothAlertOn ()
    {
        Date AlertDate = ... ; //Here I select the Alert date with a Timepicker
        alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        Intent myIntent = new Intent(main.this, AlarmReceiver.class);
        pendingIntent = PendingIntent.getBroadcast(main.this, 0, myIntent, 0);
        alarmManager.set(AlarmManager.RTC, AlertDate.getTime(), pendingIntent);
    }

    public static void SmoothAlert(final Context context)
    {
        //Here i do the Alert with Notifications etc.
    }
}
</code></pre>

<p><code>AlarmReceiver</code>:</p>

<pre><code>public class AlarmReceiver extends WakefulBroadcastReceiver
{
    static Context Alarmcontext;

    @Override
    public void onReceive(final Context context, Intent intent)
    {
        Alarmcontext = context;
        ComponentName comp = new ComponentName(context.getPackageName(),AlarmService.class.getName());
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }
}
</code></pre>

<p><code>AlarmService</code>:</p>

<pre><code>public class AlarmService extends IntentService
{
    public AlarmService()
    {
        super("AlarmService");
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
    }

    @Override
    public void onHandleIntent(Intent intent)
    {
        main.SmoothAlert(AlarmReceiver.Alarmcontext);
    }
}
</code></pre>