[mono-android] Automatic activity start
Jonathan Pryor
jonp at xamarin.com
Thu Dec 15 12:03:20 EST 2011
On Dec 15, 2011, at 11:54 AM, Martyn Wendon wrote:
> Can anybody see any problem with the following?
>
> [BroadcastReceiver]
> [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted },
> Categories = new[] { Android.Content.Intent.CategoryDefault }
> )]
> public class BootReceiver : BroadcastReceiver
> {
> public override void OnReceive(Context context, Intent intent)
> {
> Log.Debug("ReceiveBoot.OnReceive", "Received Intent " + intent.Action);
>
> if ((intent.Action != null) && (intent.Action == Android.Content.Intent.ActionBootCompleted))
> {
> Log.Debug("ReceiveBoot.OnReceive", "Received ActionBootCompleted Intent");
>
> Android.Content.Intent start = new Android.Content.Intent(context, typeof(ActivityTest));
> start.AddFlags(ActivityFlags.NewTask);
> context.ApplicationContext.StartActivity(start);
Try using context.StartActivity() instead of context.ApplicationContext.StartActivity().
Another important question is this: what platform are you running on? Honeycomb changed things so that apps won't get the BOOT_COMPLETED notification unless the user has launched the app at least once, so if you just install your app then reboot the device, you won't get the notification.
- Jon
More information about the Monodroid
mailing list