public override void Finish()
        {
            ins = null;

            base.Finish();
            OverridePendingTransition(0, 0);
        }
 protected override void OnDestroy()
 {
     ins       = null;
     detenedor = false;
     base.OnDestroy();
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            if (YoutubePlayerServerActivity.gettearinstancia() != null)
            {
                SetContentView(Resource.Layout.layoutinicio);
            }
            else
            {
                SetContentView(Resource.Layout.layoutinicioremote);
            }
            ins = this;
            ImageView botonreconocer = FindViewById <ImageView>(Resource.Id.imageView2);

            texto            = FindViewById <EditText>(Resource.Id.editText1);
            listamas         = FindViewById <RecyclerView>(Resource.Id.listamas);
            listaultimos     = FindViewById <RecyclerView>(Resource.Id.listaultimos);
            listafavoritos   = FindViewById <RecyclerView>(Resource.Id.listafavoritos);
            listasugerencias = FindViewById <RecyclerView>(Resource.Id.listasugerencias);
            List <PlaylistElement> listafake = new List <PlaylistElement>();
            var imagentipoconex = FindViewById <ImageView>(Resource.Id.tipoconexion);

            textoserver         = FindViewById <TextView>(Resource.Id.textoconexion);
            textonombreelemento = FindViewById <TextView>(Resource.Id.textoreprodactual);
            textolista          = FindViewById <TextView>(Resource.Id.textoencola);
            SetSupportActionBar(FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.my_toolbar));
            secciones = new List <LinearLayout>()
            {
                FindViewById <LinearLayout>(Resource.Id.secion1),
                FindViewById <LinearLayout>(Resource.Id.secion2),
                FindViewById <LinearLayout>(Resource.Id.secion3),
                FindViewById <LinearLayout>(Resource.Id.secion4)
            };

            foreach (var ax in secciones)
            {
                ax.Visibility = ViewStates.Gone;
            }


            SupportActionBar.Title = "Inicio";
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            itemsm = FindViewById <NavigationView>(Resource.Id.content_frame);
            sidem  = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.hambur);
            textolista.Selected          = true;
            textoserver.Selected         = true;
            textonombreelemento.Selected = true;
            if (YoutubePlayerServerActivity.gettearinstancia() != null)
            {
                isserver      = true;
                Diccfavoritos = YoutubePlayerServerActivity.gettearinstancia().listafavoritos;
                favoritos     = Diccfavoritos.Values.ToList();

                objetohistorial = YoutubePlayerServerActivity.gettearinstancia().objetohistorial;
                imagentipoconex.SetBackgroundResource(Resource.Drawable.remotecontrolbuttons);
            }
            else
            {
                isserver      = false;
                Diccfavoritos = Mainmenu.gettearinstancia().listafavoritos;
                favoritos     = Diccfavoritos.Values.ToList();
                imagentipoconex.SetBackgroundResource(Resource.Drawable.antena);
                objetohistorial = Mainmenu.gettearinstancia().objetohistorial;
            }

            if (objetohistorial == null)
            {
                objetohistorial = new History()
                {
                    Videos = new List <PlaylistElement>(),
                    Links  = new Dictionary <string, int>()
                }
            }
            ;

            if (favoritos == null)
            {
                favoritos = new List <PlaylistElement>();
            }

            if (Diccfavoritos == null)
            {
                Diccfavoritos = new Dictionary <string, PlaylistElement>();
            }



            favoritos.Reverse();
            recargarhistorial();

            new System.Threading.Thread(() =>
            {
                seteartexto();
            }).Start();



            /*    for (int i = 0; i < 20; i++)
             *  {
             *
             *      listafake.Add(new playlistelements
             *      {
             *          nombre = "klk wawawa",
             *          link = "https://www.youtube.com/watch?v=4G40N0G6lzE"
             *      });
             *  }
             */



            LinearLayoutManager enlinea = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);

            listamas.SetLayoutManager(enlinea);
            LinearLayoutManager enlinea2 = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);

            listaultimos.SetLayoutManager(enlinea2);
            LinearLayoutManager enlinea3 = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);

            listafavoritos.SetLayoutManager(enlinea3);
            LinearLayoutManager enlinea4 = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);

            listasugerencias.SetLayoutManager(enlinea4);

            adaptadorcartas adap = new adaptadorcartas(listafake, this);

            //   listafavoritos.SetAdapter(adap);
            if (YoutubePlayerServerActivity.gettearinstancia() != null)
            {
                if (System.IO.File.Exists(Constants.CachePath + "/backupplaylist.json") && !YoutubePlayerServerActivity.gettearinstancia().backupprompted)
                {
                    var snack = Snackbar.Make(FindViewById <View>(Android.Resource.Id.Content), "Desea cargar los elementos que estaba reproduciendo la vez anterior?", Snackbar.LengthIndefinite);
                    snack.SetAction("Cargar", (o) =>
                    {
                        YoutubePlayerServerActivity.gettearinstancia().loadbackupplaylist();
                        YoutubePlayerServerActivity.gettearinstancia().backupprompted = true;
                    });
                    snack.SetDuration(6000);
                    snack.Show();
                    Task.Delay(6000).ContinueWith(delegate
                    {
                        YoutubePlayerServerActivity.gettearinstancia().backupprompted = true;
                    });


                    /* new Android.Support.V7.App.AlertDialog.Builder(this)
                     * .SetTitle("Advertencia")
                     * .SetMessage("Desea cargar los elementos que estaba reproduciendo la vez anterior?")
                     * .SetPositiveButton("Si", (aa, aaa) =>
                     * {
                     * mainmenu_Offline.gettearinstancia().loadbackupplaylist();
                     * mainmenu_Offline.gettearinstancia().backupprompted = true;
                     *
                     * })
                     * .SetNegativeButton("No", (afaa, aaffa) =>
                     * {
                     *
                     * mainmenu_Offline.gettearinstancia().backupprompted = true;
                     *
                     * })
                     * .SetCancelable(false)
                     * .Create()
                     * .Show();*/
                }
                else
                {
                    YoutubePlayerServerActivity.gettearinstancia().backupprompted = true;
                }
            }

            FindViewById <CardView>(Resource.Id.cartainicio).Click += delegate
            {
                this.Finish();
            };



            texto.KeyPress += (aaxx, e) =>
            {
                if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
                {
                    // Code executed when the enter key is pressed down

                    new System.Threading.Thread(() =>
                    {
                        buscaryabrir(texto.Text);
                    }).Start();
                }
                else
                {
                    e.Handled = false;
                }
            };



            botonreconocer.Click += delegate
            {
                animar(botonreconocer);
                try
                {
                    var voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
                    voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);
                    voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 500);
                    voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 500);
                    voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 10000);
                    voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1);
                    voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.Default);
                    StartActivityForResult(voiceIntent, 7);
                }
                catch (Exception)
                {
                }
            };
            itemsm.NavigationItemSelected += (sender, e) =>
            {
                switch (e.MenuItem.TitleFormatted.ToString())
                {
                case "Reproductor":
                    this.Finish();
                    break;

                case "Control remoto":
                    this.Finish();
                    break;

                case "Navegador personalizado":
                    Intent intento = new Intent(this, typeof(customsearcheract));
                    intento.PutExtra("ipadre", "localhost");
                    intento.PutExtra("color", "black");
                    StartActivity(intento);
                    break;

                case "Conectar clientes":


                    Intent intetno = new Intent(this, typeof(qrcodigoact));
                    intetno.PutExtra("ipadre", "localhost");
                    StartActivity(intetno);


                    break;

                case "Listas de reproduccion":

                    if (YoutubePlayerServerActivity.gettearinstancia() != null)
                    {
                        Intent elint = new Intent(this, typeof(menulistaoffline));
                        elint.PutExtra("ipadre", "localhost");
                        StartActivity(elint);
                    }
                    else
                    {
                        var con = Mainmenu.gettearinstancia();
                        if (con.compatible)
                        {
                            if (con.jsonlistasremotas.Trim() != "")
                            {
                                Intent intentoo = new Intent(this, typeof(Reproducirlistaact));
                                intentoo.PutExtra("ip", "localhost");
                                StartActivity(intentoo);
                            }
                            else
                            {
                                Toast.MakeText(this, "Aun no se han recibido las listas de el servidor...", ToastLength.Long).Show();
                            }
                        }
                        else
                        {
                            Toast.MakeText(this, "Su servidor no es compatible con esta version", ToastLength.Long).Show();
                        }
                    }

                    break;
                }
                e.MenuItem.SetChecked(false);
                e.MenuItem.SetChecked(false);
                sidem.CloseDrawers();
            };
        }