I need a really simple explanation for the following:
I need a background service for my app, that runs even if the app isn't open. The examples I searched online don't work for me or my cases, so I really need detailled help here.
On the push of a button I want to start a task, that shows me instantly and all 5 minutes that it runs (I don't know what practice would be good to check this).
I know I need to work with an AlarmManager for this, but they never work. Can you make it really simple for a beginner? Thank you!
EDIT1:
public void scheduleAlarm(View V)
{
Long time = new GregorianCalendar().getTimeInMillis()+5*1000;
Intent intentAlarm = new Intent(this, AlarmReciever.class);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,time, PendingIntent.getBroadcast(this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
Toast.makeText(this, "Alarm Scheduled", Toast.LENGTH_LONG).show();
}
public class AlarmReciever extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Alarm Triggered!!!!", Toast.LENGTH_LONG).show();
}
}
I used the example in the link below and got this now. The alarm should fire the Toast every 5 seconds, right? But it doesn't do it. I see "Alarm Scheduled" but nothing happens afterwards...