jfabian
jfabian

Reputation: 41

Launch Android App using AlarmManager

I am very new to Android and I am planning to make an app that will launch at a specific time. I have read about AlarmManager, intents and Broadcast receivers. I have seen and run some sample codes from the other threads and was able to run them. Those sample are sending out notifications and text (through Toast).

But my question is, is it possible to launch my app i.e show my app's main screen on the time that I have set using the AlarmManager ? If yes, how can I do this?

I would really appreciate your help.

Thanks in advance..

Upvotes: 4

Views: 2897

Answers (1)

Muhammad Usama Shabbir
Muhammad Usama Shabbir

Reputation: 256

Yes, this is possible. The following code is working for me.

Intent intent = new Intent(this, YOUR_MAIN_ACTIVITY.class);
intent.setAction(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, ID,
                        intent, 0);

final long DELAY_IN_MILLIS = DELAY_IN_MILLI_SECONDS+ System.currentTimeMillis();
AlarmManager alarmManager = (AlarmManager)
getSystemService(Activity.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, DELAY_IN_MILLIS,pendingIntent);

Upvotes: 3

Related Questions