Xamarin.Forms 退出应用

Xamarin.Forms 退出应用

同样利用DependencyService来针对不同平台做处理:

 

 public interface ICloseAppService
 {
     void CloseApp();
 }

 

Android实现:

    public class ImpDroidCloseAppService: ICloseAppService
    {
        public void CloseApp()
        {
            Process.KillProcess(Android.OS.Process.MyPid());
        }
    }

 

iOS实现:

    public class ImpiOSCloseAppService:ICloseAppService
    {
        public void CloseApp()
        {
            Thread.CurrentThread.Abort();
        }
    }

 

UWP实现:

public class ImpUWPCloseAppService:ICloseAppService
{
    public void CloseApp()
    {
        Application.Current.Exit();
    }
}

 使用:

var _closeService = DependencyService.Get<ICloseAppService>();             
 _closeService.CloseApp();

 

posted @ 2018-02-22 16:52  Devin.Zhou  阅读(2955)  评论(0编辑  收藏  举报