0

Hello I have a short question:

"Is it possible to restart the main app constructor?" or

"Is it possible to restart a Xamarin.Forms app?"

To be more precise what I mean by this: my app checks on start if there is an internet connection, if not it displays a "oh no seems you have no connection" page.

On this page I want to have a button that restarts the app.

I tried the following:

    private void ButtonRestart_OnClicked(object sender, EventArgs e)
    {
        (Application.Current).MainPage = new LoginPage();
    }

or:

    private void ButtonRestart_OnClicked(object sender, EventArgs e)
    {
        Application.SetCurrentApplication(new App());
        App.Current.MainPage = new LoginPage();
    }

On some websites I read: "ios and the playstore do not accept apps that can restart themselves". Is that true?

Paul
  • 1
  • 2
  • 1
    I don't think re-displaying the login page would be considered "restarting" - and in any event there are numerous different ways you could handle this without "restarting". Like simply displaying a message or alert on the login page if there is no connectivity. – Jason Apr 25 '22 at 17:50
  • The ios/playstore concern is about apps that are hard to kill - that attempt to restart themselves when user kills them. Or that could go into an infinite loop of crashing and auto-restarting. What you want to do is not a problem. – ToolmakerSteve Apr 25 '22 at 23:26
  • According to this [case](https://social.msdn.microsoft.com/Forums/en-US/06a80dce-d0c7-45fb-9962-1d96044a1f0e/is-it-possible-to-restart-my-app?forum=xamarinforms), it seems that can not restart app in the ios. But in the android, you can restart the activity, but any static resource will not reload. You can check this [link](https://stackoverflow.com/questions/6609414/how-do-i-programmatically-restart-an-android-app?answertab=scoredesc#tab-top). – Liyun Zhang - MSFT Apr 26 '22 at 05:48

0 Answers0