Forum Xamarin.Forms

About installation and first launch of APK file created by Xamarin.Forms

I'm starting up as shown below, but the main screen is not displayed correctly at the first startup (main screen → license confirmation screen).

  • Multiple screens may open or a white screen may be displayed.

App.xaml

public App()
{
    try
    {
        InitializeComponent();

        Device.SetFlags(new string[] { "RadioButton_Experimental" });

        MainPage = new NavigationPage(new Menu());
    }
    catch (Exception)
    {
    }
}

Menu.xaml

public Menu()
{
    InitializeComponent();

    MacAdd = "";

    MacAdd = DependencyService.Get<IDeviceService>().GetMacAddr();

    CLic lic = new CLic();
    bool b = lic.KeyCheckAsync();
    if (b == false)
    {
        try
        {
            string kcd = lic.Get_KeyCode();
            await PopupNavigation.Instance.PushAsync(new Lic(kcd));
        }
        catch (Exception ex)
        {
        }
    }
    else
    {
    }
}

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    I notice youbool b = lic.KeyCheckAsync();, According to the method's name, this is an aync method in the construtor, if you use aync method in the construtor, it will make problem.

    when the constructor completes, the instance is still being asynchronously initialized, and there isn’t an obvious way to determine when the asynchronous initialization has completed.

    You methend get the white screen, it may be caused by it, due to I cannot reproduce this issue.

    Please google: Async OOP 2: Constructors by Stephen Cleary, here are several solution about solving this issue.
    https://blog.stephencleary.com/2013/01/async-oop-2-constructors.html

  • Techno_DevelopTechno_Develop Member ✭✭✭

    When I did it with a release build, it started normally, but when I created and installed the APK, the screen did not start normally.

    • Install from APK only once.
    • No problem when restarting the app
  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Did you refer to this steps before you release your application?

    https://docs.microsoft.com/en-us/xamarin/android/deploy-test/release-prep/?tabs=windows

    If so, when you generate the apk file like this steps

Sign In or Register to comment.