protected override void onCreate(Bundle savedInstanceState)
        {
            var file1 = "http://a.tumblr.com/tumblr_m8ueqqpyyy1rs64dko1.mp3";
            var name1 = "E43 Understanding the Dangers of Ego-Depletion by Tim";

            base.onCreate(savedInstanceState);

            var downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
            var preferenceManager = PreferenceManager.getDefaultSharedPreferences(this);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new android.widget.Button(this).AttachTo(ll);

            downloadReceiver = new MyDownloadReceiver
            {

            };

            //            O:\src\AndroidDownloadManagerActivity\Activities\ApplicationActivity___c__DisplayClass2___c__DisplayClass4.java:60: cannot find symbol
            //symbol  : class Button
            //location: class AndroidDownloadManagerActivity.Activities.ApplicationActivity___c__DisplayClass2___c__DisplayClass4
            //                    ViewExtensions.<Button>WithText(this.CS___8__locals3.b, "Download " + this.CS___8__locals3.name1);
            //                                    ^

            b.WithText("Download " + name1);
            b.AtClick(
                v =>
                {

                    b.setText("Downloading...");
                    b.setEnabled(false);

                    var downloadUri = android.net.Uri.parse(file1);

                    // http://developer.android.com/reference/android/app/DownloadManager.Request.html
                    var request = new DownloadManager.Request(downloadUri);

                    request.setTitle("idea-remixer");
                    request.setDescription(name1);

                    // W/DownloadManager(15222): Aborting request for download 166: while trying to execute request: 
                    // java.net.UnknownHostException: Unable to resolve host "a.tumblr.com": 
                    // No address associated with hostname
                    var id = downloadManager.enqueue(request);

                    Toast.makeText(this, new { id, downloadUri }.ToString(), Toast.LENGTH_LONG).show();

                    //Save the request id   

                    //var PrefEdit = preferenceManager.edit();
                    //PrefEdit.putLong(strPref_Download_ID, id);
                    //PrefEdit.commit();

                    downloadReceiver.AtReceive = delegate
                    {
                        DownloadManager.Query query = new DownloadManager.Query();
                        //query.setFilterById(preferenceManager.getLong(strPref_Download_ID, 0));
                        // http://developer.android.com/reference/android/app/DownloadManager.Query.html#setFilterById(long...)
                        query.setFilterById(new[] { id });
                        Cursor cursor = downloadManager.query(query);

                        if (cursor.moveToFirst())
                        {
                            int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
                            int status = cursor.getInt(columnIndex);

                            if (status == DownloadManager.STATUS_FAILED)
                            {
                                Toast.makeText(this, new { id, status }.ToString(), Toast.LENGTH_LONG).show();

                                b.WithText("(failed) Download " + name1);
                                b.setEnabled(true);
                            }
                            else if (status == DownloadManager.STATUS_SUCCESSFUL)
                            {
                                //Retrieve the saved request id     
                                //long downloadID = preferenceManager.getLong(strPref_Download_ID, 0);
                                var uri = downloadManager.getUriForDownloadedFile(id);


                                Toast.makeText(this, new { id, uri }.ToString(), Toast.LENGTH_LONG).show();

                                // jsc ignores this type in import?
                                Button __ref0;

                                b.WithText("Download " + name1);
                                b.setEnabled(true);

                                //ParcelFileDescriptor file;
                                //try
                                //{
                                //    file = downloadManager.openDownloadedFile(downloadID);
                                //    //FileInputStream fileInputStream       = new ParcelFileDescriptor.AutoCloseInputStream(file); 
                                //    //Bitmap bm = BitmapFactory.decodeStream(fileInputStream);
                                //    //image.setImageBitmap(bm);   
                                //}
                                //catch // (FileNotFoundException e) 
                                //{      // TODO Auto-generated catch block   
                                //    //e.printStackTrace();     
                                //    throw;
                                //}
                            }
                        }
                    };

                }
            );


            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            new Button(this)
                .WithText("Create Event!")
                .AttachTo(ll)
                .AtClick(
                    b =>
                    {
                        b.setText("Done!");

                        // http://developer.android.com/reference/android/provider/CalendarContract.EventsColumns.html#DESCRIPTION

                        Intent calIntent = new Intent(Intent.ACTION_INSERT);
                        calIntent.setType("vnd.android.cursor.item/event");
                        calIntent.putExtra("title", "My House Party");
                        calIntent.putExtra("eventLocation", "My Beach House");
                        calIntent.putExtra("description", "A Pig Roast on the Beach");

                        GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15);
                        calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
                        calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                             calDate.getTimeInMillis());
                        calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                             calDate.getTimeInMillis());





                        //ttdw


                        calIntent.putExtra("accessLevel", 0x00000002);
                        calIntent.putExtra("availability", 0x00000000);

                        calIntent.putExtra("rrule", "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH");

                        startActivity(calIntent);
                    }
            );

            var COLS = new[]
            { 
                "title",
                "dtstart"
            };


            var at = new TextView(this).AttachTo(ll);

            at.setText("at " + CalendarContract.Events.CONTENT_URI.ToString());

            // from t in calendars
            // select t.title

            var mCursor = this.getContentResolver().query(
                CalendarContract.Events.CONTENT_URI, COLS, null, null, null
            );

            mCursor.moveToLast();

            var tv = new TextView(this).AttachTo(ll);
            tv.setText("n/a");
            Action update =
                delegate
                {
                    var title = "";
                    var start = "";
                    var w = "";

                    //Format df = android.text.format.DateFormat.getDateFormat(this);
                    //Format tf = android.text.format.DateFormat.getTimeFormat(this);

                    //try
                    //{
                    title = mCursor.getString(0);
                    start = ((object)mCursor.getLong(1)).ToString();


                    w += title;
                    w += " at ";
                    w += start;

                    tv.setText(w);
                    //}
                    //catch
                    //{
                    //    tv.setText("n/a error");

                    //    throw;
                    //}



                };

            Button prev, next = null;

            prev = new Button(this)
                  .WithText("Prev")
                  .AttachTo(ll)
                  .AtClick(
                      b =>
                      {
                          if (!mCursor.isFirst())
                          {
                              mCursor.moveToPrevious();
                              next.setEnabled(true);
                          }
                          else
                              b.setEnabled(false);

                          update();
                      }
            );

            next = new Button(this)
                .WithText("Next")
                .AttachTo(ll)
                .AtClick(
                    b =>
                    {

                        if (!mCursor.isLast())
                        {
                            mCursor.moveToNext();
                            prev.setEnabled(true);
                        }
                        else
                            b.setEnabled(false);

                        update();
                    }
          );

            update();


            this.setContentView(sv);
        }
        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // this activity 
            // check for db table
            // 
            //  shall resume on boot
            //  shall recheck every n seconds
            //  shall remember the last result
            //  shall remember how many iterations
            //  shall remember how many boots

            base.onCreate(savedInstanceState);

            #region setContentView
            ScrollView sv = new ScrollView(this);
            LinearLayout ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var that = (Context)this;

            this.CancelPendingAlarm(NotifyServiceFromTimer.Class);


            #region startservice
            startservice = new Button(this);
            startservice.setText("Start Timer");
            startservice.setOnClickListener(
                new startservice_onclick { that = this }
            );
            ll.addView(startservice);
            #endregion

            #region stopservice
            stopservice = new Button(this);
            stopservice.setText("Stop Timer");
            stopservice.setEnabled(false);
            stopservice.setOnClickListener(
                new stopservice_onclick { that = this }
            );
            ll.addView(stopservice);
            #endregion


            CheckBox cb = new CheckBox(this);

            cb.setText("Start the timer earlier!");
            cb.setOnCheckedChangeListener(new cb_onchanged { that = this });

            __SQLiteConnectionHack.Context = this;

            using (var c = new SQLiteConnection(AbstractNotifyService.ConnectionString))
            {
                c.Open();

                var MyDataTable = new MyDataTable(c);

                cb.setChecked(MyDataTable.StartEarlier == 1);

                c.Close();


            }

            ll.addView(cb);

            this.setContentView(sv);
            #endregion



            var intent = new Intent(this, NotifyServiceFromActivity.Class);
            this.startService(intent);

        }
        // https://github.com/opersys/raidl


        // http://stackoverflow.com/questions/6274141/trigger-background-service-at-a-specific-time-in-android
        // http://stackoverflow.com/questions/7144908/how-is-an-intent-service-declared-in-the-android-manifest
        // http://developer.android.com/guide/topics/manifest/service-element.html

        // https://github.com/android/platform_frameworks_base/blob/master/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java

        //AtBootCompleted hack1;

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);

            #region startservice
            var startservice = new Button(this);
            startservice.setText("Start Service to send Notification");
            startservice.AtClick(
                delegate
                {
                    startservice.setEnabled(false);
                    //this.ShowToast("startservice_onclick");

                    //var intent = new Intent(this, NotifyService.Class);
                    var intent = new Intent(this, typeof(NotifyService).ToClass());
                    this.startService(intent);

                    // http://developer.android.com/reference/android/app/Activity.html#recreate%28%29
                    this.recreate();
                }
            );
            ll.addView(startservice);
            #endregion

            #region stopservice
            var stopservice = new Button(this);
            stopservice.setText("Stop Service");
            stopservice.AtClick(
                delegate
                {
                    this.ShowToast("stopservice_onclick");

                    var intent = new Intent();
                    intent.setAction(NotifyService.ACTION);
                    intent.putExtra("RQS", NotifyService.RQS_STOP_SERVICE);
                    this.sendBroadcast(intent);

                    // seems stop takes a while

                    //Task.Delay(100);

                    Thread.Sleep(30);

                    this.recreate();
                }
            );
            ll.addView(stopservice);
            #endregion

            stopservice.setEnabled(false);

            // http://stackoverflow.com/questions/12891903/android-check-if-my-service-is-running-in-the-background
            var m = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);


            Console.WriteLine("getRunningServices");

            var s = m.getRunningServices(1000);

            Console.WriteLine("getRunningServices " + s.size());

            var se =
                // http://stackoverflow.com/questions/7170730/how-to-set-a-control-panel-for-my-service-in-android

                from i in Enumerable.Range(0, s.size())
                let rsi = (android.app.ActivityManager.RunningServiceInfo)s.get(i)
                let cn = rsi.service.getClassName()
                let cp = m.getRunningServiceControlPanel(rsi.service)

                //orderby cn
                orderby cp != null

                select new { i, rsi, cn, cp };
            //java.lang.JavaSystem.ex
            //     I/System.Console( 1617): { i = 45, cn = android.hardware.location.GeofenceHardwareService, cp =  }
            //I/System.Console( 1617): { i = 17, cn = ccc71.at.services.at_service, cp =  }
            //I/System.Console( 1617): { i = 34, cn = com.android.bluetooth.a2dp.A2dpService, cp =  }
            //I/System.Console( 1617): { i = 13, cn = com.android.bluetooth.btservice.AdapterService, cp =  }
            //I/System.Console( 1617): { i = 23, cn = com.android.bluetooth.gatt.GattService, cp =  }
            //I/System.Console( 1617): { i = 68, cn = com.android.bluetooth.hfp.HeadsetService, cp =  }
            //I/System.Console( 1617): { i = 0, cn = com.android.bluetooth.hid.HidService, cp =  }
            //I/System.Console( 1617): { i = 84, cn = com.android.bluetooth.pan.PanService, cp =  }
            //I/System.Console( 1617): { i = 80, cn = com.android.defcontainer.DefaultContainerService, cp =  }
            //I/System.Console( 1617): { i = 37, cn = com.android.incallui.InCallServiceImpl, cp =  }
            //I/System.Console( 1617): { i = 71, cn = com.android.incallui.MCIDService, cp =  }
            //I/System.Console( 1617): { i = 55, cn = com.android.incallui.SecInCallService, cp =  }
            //I/System.Console( 1617): { i = 73, cn = com.android.internal.backup.LocalTransportService, cp =  }
            //I/System.Console( 1617): { i = 81, cn = com.android.phone.TelephonyDebugService, cp =  }
            //I/System.Console( 1617): { i = 66, cn = com.android.providers.media.MtpService, cp =  }
            //I/System.Console( 1617): { i = 65, cn = com.android.server.DrmEventService, cp =  }
            //I/System.Console( 1617): { i = 57, cn = com.android.server.telecom.BluetoothPhoneService, cp =  }
            //I/System.Console( 1617): { i = 50, cn = com.android.server.telecom.BluetoothVoIPService, cp =  }
            //I/System.Console( 1617): { i = 62, cn = com.android.stk.StkAppService, cp =  }
            //I/System.Console( 1617): { i = 15, cn = com.android.systemui.ImageWallpaper, cp = PendingIntent{2759cef2: android.os.BinderProxy@181ef173} }
            //I/System.Console( 1617): { i = 44, cn = com.android.systemui.SystemUIService, cp =  }
            //I/System.Console( 1617): { i = 12, cn = com.android.systemui.keyguard.KeyguardService, cp =  }
            //I/System.Console( 1617): { i = 21, cn = com.dsi.ant.server.AntService, cp =  }
            //I/System.Console( 1617): { i = 48, cn = com.fmm.dm.XDMService, cp =  }
            //I/System.Console( 1617): { i = 22, cn = com.google.android.gms.analytics.service.AnalyticsService, cp =  }
            //I/System.Console( 1617): { i = 51, cn = com.google.android.gms.auth.trustagent.GoogleTrustAgent, cp =  }
            //I/System.Console( 1617): { i = 86, cn = com.google.android.gms.backup.BackupTransportService, cp =  }
            //I/System.Console( 1617): { i = 4, cn = com.google.android.gms.car.CarService, cp =  }
            //I/System.Console( 1617): { i = 76, cn = com.google.android.gms.clearcut.service.ClearcutLoggerService, cp =  }
            //I/System.Console( 1617): { i = 75, cn = com.google.android.gms.common.stats.GmsCoreStatsService, cp =  }
            //I/System.Console( 1617): { i = 67, cn = com.google.android.gms.deviceconnection.service.DeviceConnectionServiceBroker, cp =  }
            //I/System.Console( 1617): { i = 19, cn = com.google.android.gms.gcm.GcmService, cp =  }
            //I/System.Console( 1617): { i = 38, cn = com.google.android.gms.gcm.http.GoogleHttpService, cp =  }
            //I/System.Console( 1617): { i = 74, cn = com.google.android.gms.playlog.service.PlayLogBrokerService, cp =  }
            //I/System.Console( 1617): { i = 18, cn = com.google.android.gms.trustagent.api.trustagent.GoogleTrustAgentService, cp =  }
            //I/System.Console( 1617): { i = 25, cn = com.google.android.gms.usagereporting.service.UsageReportingService, cp =  }
            //I/System.Console( 1617): { i = 82, cn = com.google.android.gms.wearable.service.WearableService, cp =  }
            //I/System.Console( 1617): { i = 40, cn = com.google.android.hotword.service.HotwordService, cp =  }
            //I/System.Console( 1617): { i = 60, cn = com.google.android.libraries.hangouts.video.VideoChatService, cp =  }
            //I/System.Console( 1617): { i = 30, cn = com.google.android.location.fused.FusedLocationService, cp =  }
            //I/System.Console( 1617): { i = 16, cn = com.google.android.location.geocode.GeocodeService, cp =  }
            //I/System.Console( 1617): { i = 39, cn = com.google.android.location.geofencer.service.GeofenceProviderService, cp =  }
            //I/System.Console( 1617): { i = 63, cn = com.google.android.location.internal.GoogleLocationManagerService, cp =  }
            //I/System.Console( 1617): { i = 54, cn = com.google.android.location.internal.PendingIntentCallbackService, cp =  }
            //I/System.Console( 1617): { i = 58, cn = com.google.android.location.internal.server.GoogleLocationService, cp =  }
            //I/System.Console( 1617): { i = 61, cn = com.google.android.location.network.NetworkLocationService, cp =  }
            //I/System.Console( 1617): { i = 3, cn = com.google.android.music.dial.DialMediaRouteProviderService, cp =  }
            //I/System.Console( 1617): { i = 6, cn = com.google.android.search.core.service.BroadcastListenerService, cp =  }
            //I/System.Console( 1617): { i = 35, cn = com.google.android.search.core.service.SearchService, cp =  }
            //I/System.Console( 1617): { i = 69, cn = com.google.android.voiceinteraction.GsaVoiceInteractionService, cp =  }
            //I/System.Console( 1617): { i = 85, cn = com.ime.framework.spellcheckservice.SamsungIMESpellCheckerService, cp =  }
            //I/System.Console( 1617): { i = 49, cn = com.samsung.android.MtpApplication.MtpService, cp =  }
            //I/System.Console( 1617): { i = 78, cn = com.samsung.android.app.catchfavorites.catchnotifications.CatchNotificationsService, cp = PendingIntent{1f770943: android.os.BinderProxy@6924ca9} }
            //I/System.Console( 1617): { i = 56, cn = com.samsung.android.app.edge.nightclock.NightClockService, cp =  }
            //I/System.Console( 1617): { i = 59, cn = com.samsung.android.app.galaxyfinder.recommended.RecommendedService, cp =  }
            //I/System.Console( 1617): { i = 53, cn = com.samsung.android.app.galaxyfinder.tag.TagReadyService, cp =  }
            //I/System.Console( 1617): { i = 72, cn = com.samsung.android.app.shealth.tracker.pedometer.service.PedometerService, cp =  }
            //I/System.Console( 1617): { i = 32, cn = com.samsung.android.app.shealth.tracker.sport.livetracker.LiveTrackerService, cp =  }
            //I/System.Console( 1617): { i = 79, cn = com.samsung.android.beaconmanager.BeaconService, cp =  }
            //I/System.Console( 1617): { i = 42, cn = com.samsung.android.health.wearable.service.WearableService, cp =  }
            //I/System.Console( 1617): { i = 70, cn = com.samsung.android.providers.context.ContextService, cp =  }
            //I/System.Console( 1617): { i = 24, cn = com.samsung.android.scloud.auth.RelayService, cp =  }
            //I/System.Console( 1617): { i = 26, cn = com.samsung.android.sconnect.periph.PeriphService, cp =  }
            //I/System.Console( 1617): { i = 29, cn = com.samsung.android.sensor.framework.SensorService, cp =  }
            //I/System.Console( 1617): { i = 64, cn = com.samsung.android.service.health.HealthService, cp =  }
            //I/System.Console( 1617): { i = 14, cn = com.samsung.android.service.peoplestripe.PeopleNotiListenerService, cp = PendingIntent{17538bc0: android.os.BinderProxy@6924ca9} }
            //I/System.Console( 1617): { i = 77, cn = com.samsung.android.service.peoplestripe.PeopleStripeService, cp =  }
            //I/System.Console( 1617): { i = 28, cn = com.samsung.android.sm.widgetapp.SMWidgetService, cp =  }
            //I/System.Console( 1617): { i = 47, cn = com.samsung.android.thememanager.ThemeManagerService, cp =  }
            //I/System.Console( 1617): { i = 52, cn = com.samsung.appcessory.server.SAPService, cp =  }
            //I/System.Console( 1617): { i = 5, cn = com.samsung.hs20settings.WifiHs20UtilityService, cp =  }
            //I/System.Console( 1617): { i = 41, cn = com.samsung.sec.android.application.csc.CscUpdateService, cp =  }
            //I/System.Console( 1617): { i = 2, cn = com.sec.android.app.bluetoothtest.BluetoothBDTestService, cp =  }
            //I/System.Console( 1617): { i = 31, cn = com.sec.android.app.launcher.services.LauncherService, cp =  }
            //I/System.Console( 1617): { i = 10, cn = com.sec.android.daemonapp.ap.accuweather.WeatherClockService, cp =  }
            //I/System.Console( 1617): { i = 8, cn = com.sec.android.inputmethod.SamsungKeypad, cp = PendingIntent{39a730f9: android.os.BinderProxy@2b45775c} }
            //I/System.Console( 1617): { i = 46, cn = com.sec.android.pagebuddynotisvc.PageBuddyNotiSvc, cp =  }
            //I/System.Console( 1617): { i = 1, cn = com.sec.android.sensor.framework.SensorService, cp =  }
            //I/System.Console( 1617): { i = 83, cn = com.sec.android.service.sm.service.SecurityManagerService, cp =  }
            //I/System.Console( 1617): { i = 7, cn = com.sec.android.widgetapp.ap.weather.common.appservice.WeatherScreenService, cp =  }
            //I/System.Console( 1617): { i = 11, cn = com.sec.android.widgetapp.ap.weather.common.appservice.WeatherService, cp =  }
            //I/System.Console( 1617): { i = 36, cn = com.sec.android.widgetapp.ap.weather.widget.surfacewidget.WeatherSurfaceWidget, cp =  }
            //I/System.Console( 1617): { i = 33, cn = com.sec.android.widgetapp.digitalclockeasy.DigitalClockEasyService, cp =  }
            //I/System.Console( 1617): { i = 9, cn = com.sec.bcservice.BroadcastService, cp =  }
            //I/System.Console( 1617): { i = 20, cn = com.sec.enterprise.mdm.services.simpin.EnterpriseSimPin, cp =  }
            //I/System.Console( 1617): { i = 87, cn = com.sec.phone.SecPhoneService, cp =  }
            //I/System.Console( 1617): { i = 43, cn = com.sec.spp.push.PushClientService, cp =  }
            //I/System.Console( 1617): { i = 27, cn = org.simalliance.openmobileapi.service.SmartcardService, cp =  }

            //I/System.Console( 5883): { i = 85, cn = com.google.android.gms.backup.BackupTransportService, process = com.google.android.gms.persistent }
            //I/System.Console( 5883): { i = 86, cn = com.sec.phone.SecPhoneService, process = com.sec.phone }
            //I/System.Console( 5883): { i = 7, cn = com.sec.android.inputmethod.SamsungKeypad, process = com.sec.android.inputmethod, cp = PendingIntent{e6c79e2: android.os.BinderProxy@181ef173}, describeContents = 0 }
            //I/System.Console( 5883): { i = 13, cn = com.samsung.android.service.peoplestripe.PeopleNotiListenerService, process = com.samsung.android.service.peoplestripe, cp = PendingIntent{24b00830: android.os.BinderProxy@6924ca9}, describeContents = 0 }
            //I/System.Console( 5883): { i = 14, cn = com.android.systemui.ImageWallpaper, process = com.android.systemui.imagewallpaper, cp = PendingIntent{135c522e: android.os.BinderProxy@1ced31cf}, describeContents = 0 }
            //I/System.Console( 5883): { i = 77, cn = com.samsung.android.app.catchfavorites.catchnotifications.CatchNotificationsService, process = com.samsung.android.app.catchfavorites, cp = PendingIntent{2b45775c: android.os.BinderProxy@6924ca9}, describeContents = 0 }

            // http://stackoverflow.com/questions/7170730/how-to-set-a-control-panel-for-my-service-in-android
            // The service's description and configuration intent can be set during a service binding
            foreach (var ss in se)
            {


                var cn = ss.cn;

                PendingIntent cp = ss.cp;

                // whats a ControlPanel ?

                //  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.app.PendingIntent.describeContents()' on a null object reference

                if (cp == null)
                    Console.WriteLine(new { ss.i, cn, ss.rsi.process });
                else
                    Console.WriteLine(new { ss.i, cn, ss.rsi.process, cp, describeContents = cp.describeContents() });

                // I/System.Console(17713): { cn = AndroidBootServiceNotificationActivity.Activities.NotifyService }
                if (cn == typeof(NotifyService).FullName)
                {
                    // cannot find ourself? unless its running

                    startservice.setEnabled(false);
                    stopservice.setEnabled(true);

                    // its running

                    // http://stackoverflow.com/questions/7170730/how-to-set-a-control-panel-for-my-service-in-android
                    // http://www.techques.com/question/1-7170730/How-to-set-a-control-panel-for-my-Service-in-Android
                    // http://alvinalexander.com/java/jwarehouse/android/core/java/android/app/ActivityManagerNative.java.shtml
                }


                #region cp
                if (cp != null)
                {
                    // could we not infer activity from code from application?

                    new Button(this).WithText(
                        cn
                    ).AtClick(
                        delegate
                        {
                            // http://codetheory.in/android-pending-intents/
                            try
                            {
                                cp.send();
                            }
                            catch
                            {
                            }

                            //this.startActivity(
                            //    cp
                            //);
                        }
                    ).AttachTo(ll);
                }
                #endregion


            }

            this.setContentView(sv);

            //this.ShowToast("http://jsc-solutions.net");


            new Button(this).WithText("exit").AttachTo(ll).AtClick(
                delegate
                {

                    // will it be logged?
                    System.Environment.Exit(13);

                    // application still visible in tasks?
                }
            );

            new Button(this).WithText("finish").AttachTo(ll).AtClick(
               delegate
               {
                   //this.finishAndRemoveTask();
                   this.finish();

                   // will it be logged?
                   //System.Environment.Exit(13);

                   // application still visible in tasks?
               }
           );

            new Button(this).WithText("finishAndRemoveTask").AttachTo(ll).AtClick(
             delegate
             {
                 this.finishAndRemoveTask();
                 //this.finish();

                 // will it be logged?
                 //System.Environment.Exit(13);

                 // application still visible in tasks?
             }
         );
        }
        // test via
        // X:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPSendAsync\ChromeUDPSendAsync\Application.cs
        // how do we know its running?

        // x:\util\android-sdk-windows\platform-tools\adb.exe logcat -s "DEBUG" "System.Console"
        // "x:\util\android-sdk-windows\platform-tools\adb.exe" connect 192.168.1.126:5555

        // https://github.com/opersys/raidl


        // http://stackoverflow.com/questions/6274141/trigger-background-service-at-a-specific-time-in-android
        // http://stackoverflow.com/questions/7144908/how-is-an-intent-service-declared-in-the-android-manifest
        // http://developer.android.com/guide/topics/manifest/service-element.html

        //AtBootCompleted hack1;

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);

            #region startservice
            var startservice = new Button(this);
            startservice.setText("Start Service");
            startservice.AtClick(
                delegate
            {
                startservice.setEnabled(false);
                //this.ShowToast("startservice_onclick");

                //var intent = new Intent(this, NotifyService.Class);
                var intent = new Intent(this, typeof(NotifyService).ToClass());
                this.startService(intent);

                // http://developer.android.com/reference/android/app/Activity.html#recreate%28%29
                //this.recreate();
                this.finish();
            }
            );
            ll.addView(startservice);
            #endregion

            #region stopservice
            var stopservice = new Button(this);
            stopservice.setText("Stop Service");
            stopservice.AtClick(
                delegate
            {
                this.ShowToast("stopservice_onclick");

                var intent = new Intent();
                intent.setAction(NotifyService.ACTION);
                intent.putExtra("RQS", NotifyService.RQS_STOP_SERVICE);
                this.sendBroadcast(intent);

                // seems stop takes a while

                //Task.Delay(100);

                Thread.Sleep(30);

                this.recreate();
            }
            );
            ll.addView(stopservice);
            #endregion

            stopservice.setEnabled(false);

            // http://stackoverflow.com/questions/12891903/android-check-if-my-service-is-running-in-the-background
            var m = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);


            Console.WriteLine("getRunningServices");

            var s = m.getRunningServices(1000);

            Console.WriteLine("getRunningServices " + s.size());

            var se = Enumerable.Range(0, s.size()).Select(i => (android.app.ActivityManager.RunningServiceInfo)s.get(i));

            foreach (var ss in se)
            {


                var cn = ss.service.getClassName();

                Console.WriteLine(new { cn });

                // I/System.Console(17713): { cn = AndroidServiceUDPNotification.Activities.NotifyService }
                if (cn == typeof(NotifyService).FullName)
                {

                    startservice.setEnabled(false);
                    stopservice.setEnabled(true);

                    // its running

                    // http://stackoverflow.com/questions/7170730/how-to-set-a-control-panel-for-my-service-in-android
                    // http://www.techques.com/question/1-7170730/How-to-set-a-control-panel-for-my-Service-in-Android
                    // http://alvinalexander.com/java/jwarehouse/android/core/java/android/app/ActivityManagerNative.java.shtml

#if XCONTROLPANEL
                    PendingIntent cp = m.getRunningServiceControlPanel(ss.service);

                    Console.WriteLine(new { cp });
                    if (cp != null)
                    {
                    #region cpb
                        var cpb = new Button(this);
                        cpb.setText("ServiceControlPanel");
                        cpb.AtClick(
                            delegate
                            {
                                //new Intent(
                                //PendingIntent.getActivity(
                                //startActivity(cp);

                                // http://iserveandroid.blogspot.com/2011/03/how-to-launch-pending-intent.html
                                Intent intent = new Intent();

                                try
                                {
                                    cp.send(this, 0, intent);
                                }
                                catch
                                {

                                    throw;
                                }

                            }
                        );
                        ll.addView(cpb);
                    }
                    #endregion
#endif



                }
            }

            this.setContentView(sv);

            this.ShowToast("http://jsc-solutions.net");


        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            var file1 = "http://a.tumblr.com/tumblr_m8ueqqpyyy1rs64dko1.mp3";
            var name1 = "E43 Understanding the Dangers of Ego-Depletion by Tim";

            base.onCreate(savedInstanceState);

            var downloadManager   = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
            var preferenceManager = PreferenceManager.getDefaultSharedPreferences(this);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);

            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new android.widget.Button(this).AttachTo(ll);

            downloadReceiver = new MyDownloadReceiver
            {
            };

            //            O:\src\AndroidDownloadManagerActivity\Activities\ApplicationActivity___c__DisplayClass2___c__DisplayClass4.java:60: cannot find symbol
            //symbol  : class Button
            //location: class AndroidDownloadManagerActivity.Activities.ApplicationActivity___c__DisplayClass2___c__DisplayClass4
            //                    ViewExtensions.<Button>WithText(this.CS___8__locals3.b, "Download " + this.CS___8__locals3.name1);
            //                                    ^

            b.WithText("Download " + name1);
            b.AtClick(
                v =>
            {
                b.setText("Downloading...");
                b.setEnabled(false);

                var downloadUri = android.net.Uri.parse(file1);

                // http://developer.android.com/reference/android/app/DownloadManager.Request.html
                var request = new DownloadManager.Request(downloadUri);

                request.setTitle("idea-remixer");
                request.setDescription(name1);

                // W/DownloadManager(15222): Aborting request for download 166: while trying to execute request:
                // java.net.UnknownHostException: Unable to resolve host "a.tumblr.com":
                // No address associated with hostname
                var id = downloadManager.enqueue(request);

                Toast.makeText(this, new { id, downloadUri }.ToString(), Toast.LENGTH_LONG).show();

                //Save the request id

                //var PrefEdit = preferenceManager.edit();
                //PrefEdit.putLong(strPref_Download_ID, id);
                //PrefEdit.commit();

                downloadReceiver.AtReceive = delegate
                {
                    DownloadManager.Query query = new DownloadManager.Query();
                    //query.setFilterById(preferenceManager.getLong(strPref_Download_ID, 0));
                    // http://developer.android.com/reference/android/app/DownloadManager.Query.html#setFilterById(long...)
                    query.setFilterById(new[] { id });
                    Cursor cursor = downloadManager.query(query);

                    if (cursor.moveToFirst())
                    {
                        int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
                        int status      = cursor.getInt(columnIndex);

                        if (status == DownloadManager.STATUS_FAILED)
                        {
                            Toast.makeText(this, new { id, status }.ToString(), Toast.LENGTH_LONG).show();

                            b.WithText("(failed) Download " + name1);
                            b.setEnabled(true);
                        }
                        else if (status == DownloadManager.STATUS_SUCCESSFUL)
                        {
                            //Retrieve the saved request id
                            //long downloadID = preferenceManager.getLong(strPref_Download_ID, 0);
                            var uri = downloadManager.getUriForDownloadedFile(id);


                            Toast.makeText(this, new { id, uri }.ToString(), Toast.LENGTH_LONG).show();

                            // jsc ignores this type in import?
                            Button __ref0;

                            b.WithText("Download " + name1);
                            b.setEnabled(true);

                            //ParcelFileDescriptor file;
                            //try
                            //{
                            //    file = downloadManager.openDownloadedFile(downloadID);
                            //    //FileInputStream fileInputStream       = new ParcelFileDescriptor.AutoCloseInputStream(file);
                            //    //Bitmap bm = BitmapFactory.decodeStream(fileInputStream);
                            //    //image.setImageBitmap(bm);
                            //}
                            //catch // (FileNotFoundException e)
                            //{      // TODO Auto-generated catch block
                            //    //e.printStackTrace();
                            //    throw;
                            //}
                        }
                    }
                };
            }
                );


            this.setContentView(sv);
        }