I added a public method to return variable pageLoaded but visual studio shows this error "An object reference is needed by the method MainPage.PageLoaded() not static". The logic is to finish Splash Activiy only if pageLoaded be true. If someone has a better idea for this, would be nice to know, I'm just started learning C#/Xamarin.
My code:
namespace MyApp
{
public partial class MainPage : ContentPage
{
private bool pageLoaded = false;
public MainPage()
{
InitializeComponent();
webnav.HeightRequest = 1000;
webnav.WidthRequest = 1000;
webnav.Source = "https://www.example.com";
}
public void Webnav_Navigated(object sender, WebNavigatedEventArgs e)
{
pageLoaded = true;
}
public bool PageLoaded()
{
return pageLoaded;
}
}
}
Code 2:
...
...
using MyApp;
namespace MyApp.Droid
{
[Activity(Label = "My App", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
while (true)
{
if (MainPage.PageLoaded())
{
SplashScreen.fa.Finish();
break;
}
}
}
}
}