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();