0

Xamarin forms using Visual Studio 2017 Community

Already Tried from this most upvoted Question and Anwser

But probably I am not getting direct help for its implementation. Tried a lot but could not make the exact derivatives to call for ICloseApplication and (Activity) (Sorry very new to this) Created Class and interface. But could not go later forward. So if anyone can give me some more detail hint in this resolution or any other example it would be great.

public class CloseApplication : ICloseApplication
{
    public void closeApplication()
    {
        var activity = (Activity)Forms.Context;
        activity.FinishAffinity();
    }
}

public interface ICloseApplication
{
    void closeApplication();
}

I have initially tried:-

private async void CheckConnection()
{
     if (Sql_Common.CheckConnection() == false)
     {
          await DisplayAlert("Network Error!", "Network connection could not be establised to server!", "ok");
          System.Diagnostics.Process.GetCurrentProcess().Kill();
     }
}

The code in class for CheckConnection:-

public static bool CheckConnection()
{
    if (CrossConnectivity.Current.IsConnected)
        return true;
    else
        return false;
}

But it did not quit the application but stayed intact (as if in hang up state) I know I am very near the solution and tried my best but the resolution is not coming.

How about ? (Got from one search) Trying this out till then

Application.Current.Quit();

My main aim:- I want to test at initial level whether the network connection is there or not. If it is not there then it should show a dialog message for No network and exit out from application.

Yeshwant Mudholkar
  • 107
  • 1
  • 2
  • 10
  • 1
    Why would you want to do this? Why not just display a message to the user and then wait until connectivity is restored? Explicitly exiting the app is not good UX. – Jason Sep 22 '18 at 18:52
  • @Jason : Super Advice! Thank you very much! You are absolutely right. I have placed the code under Welcome Button. If network is detected, it would proceed further or else it would update a DisplayAlert message and return; ! Its Working smooth now as expected. – Yeshwant Mudholkar Sep 23 '18 at 12:12

0 Answers0