Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

App only runs when emulator is in sleep mode first

$
0
0

Hi all,

I am working on a small Xamarin.Forms webview application. This is a follow up question to the one answered on Stackoverflow xamarin-forms-making-webview-go-back

So I have a toolbar and a back button implemented and working. But when I run the program with the emulator already open(im using Genymotion), the program runs and shows the toolbar along with the back button...but no webview will display.

But heres the strange thing, when I run the program when the emulator is in sleep mode and then switch it back on the program works perfectly. Also, when I tested it on iOS it just showed the toolbar and no webview at all!

Abit confusing I know but can anyone help me out with this. I dont know if its just an emulator issue or what.

I will attach my code below:

App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;

namespace WebView_form
{
    public class App : Application
    {
        public App()
        {
            //const string URL = "http://www.google.com";
            MainPage = new NavigationPage(new WebPage());
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

WebPage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;

using Xamarin.Forms;

namespace WebView_form
{
    public class WebPage : ContentPage
    {
        private WebView webView;

        public WebPage()
        {
            webView = new WebView 
            {
                Source = "https://www.google.com"
            };


            // toolbar
            ToolbarItems.Add(new ToolbarItem("Back", null, () =>
                {
                    webView.GoBack();
                }));

            Content = new StackLayout
            {
                Children = { webView }
            };
        }
    }
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>