Thursday, June 9, 2011

[android-developers] Start an external activity from a BroadcastReceiver

Hello folks,

after googling all the day, I have solution to actually start an
external activity from a receiver.
In the end I added a service to the package, so the receiver starts
the service and the service should start the activity. Of course that
doesn't sound very efficient at all, but in addition to this it
doesn't work either. Thats my code from the service:

public void onCreate() {
super.onCreate();
Intent i = new Intent("android.intent.action.MAIN");
ComponentName n = new
ComponentName("com.schwimmer.android.carmode",
"com.schwimmer.android.carmode.ToggleCarMode");
i.setComponent(n);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(i);
//this.stopSelf();

If I put this code into an activity and start it wit
this.startActivity() it works like a charm. But not if it is put into
the receiver or server.

Do you have any idea how to fix that?

Thanks!
Marc

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment