I am trying to start an activity at a certain time with the help of a service and broadcastreceiver. The problem is, once the time hits, my app crashes.
Here\'s my Alarm
I would like to point out that starting activities from the background is not a great experience for the user. Suppose the user is in the midst of some other work? Arbitrarily starting a new Activity is at the very least an annoyance.
I think that what you should do is send a notification from your Service, with a content Intent leads to the activity you want to start. This gives users the choice to go to the activity as soon as the notification appears or wait until they're finished with their current work before going to the activity.
Perhaps I've misunderstood what you want to do, but you may want to consider amending your app design.
The Notifications API guide discusses this in more detail. There's also an Android training class called Notifying the User
To start an Activity
outside of an Activity
Context
you need to use the flag FLAG_ACTIVITY_NEW_TASK
. Add this to your Intent
Intent in = new Intent(this, GoTime.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if this doesn't solve your problem then please post the logcat.
Intent