Issue
I was testing what I done with android emulator and it always worked well but yesterday it suddenly shows my app as a just white blank screen. I dont know the reason why. This my MainActivity class
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Xamarin.Forms;
namespace HealthCareApp.Droid
{
[Activity(Label = "HealthCareApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
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);
Forms.SetFlags("Brush_Experimental");
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new Xamarin.Forms.Application());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
App.xaml.cs ( now its giving a error : "initializecomponent is inaccessible due to its protection level" )
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace HealthCareApp
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new LoginPage());
}
protected override void OnStart()
{
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
}
}
}
Solution
You should have a App
class somewhere in your project, which contains information of which Forms page to show first and setup stuff like services in a IoC container etc.
Instead of calling
LoadApplication(new Xamarin.Forms.Application());
You should probably call:
LoadApplication(new App());
Answered By - Cheesebaron
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.