/// <summary> /// Terminates the application if it is running on background. /// </summary> /// <param name="app">ApplicationRunningContext object</param> /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when failed because of permission denied.</exception> /// <exception cref="InvalidOperationException">Thrown when failed because of system error.</exception> /// <privilege>http://tizen.org/privilege/appmanager.kill.bgapp</privilege> /// <remarks> /// This function returns after it just sends a request for terminating a background application. /// Platform will decide if the target application could be terminated or not according to the state of the target application. /// </remarks> /// <since_tizen> 6 </since_tizen> public static void TerminateBackgroundApplication(ApplicationRunningContext app) { ErrorCode err = Interop.ApplicationManager.AppManagerRequestTerminateBgApp(app._contextHandle); if (err != Interop.ApplicationManager.ErrorCode.None) { switch (err) { case Interop.ApplicationManager.ErrorCode.InvalidParameter: throw new ArgumentException("Invalid argument."); case Interop.ApplicationManager.ErrorCode.PermissionDenied: throw new UnauthorizedAccessException("Permission denied."); default: throw new InvalidOperationException("Invalid Operation."); } } }
private static void RegisterApplicationChangedEvent() { Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None; s_applicationChangedEventCallback = (IntPtr contextHandle, Interop.ApplicationManager.AppContextEvent state, IntPtr userData) => { if (contextHandle == IntPtr.Zero) { return; } IntPtr clonedHandle = IntPtr.Zero; err = Interop.ApplicationManager.AppContextClone(out clonedHandle, contextHandle); if (err != Interop.ApplicationManager.ErrorCode.None) { throw ApplicationManagerErrorFactory.GetException(err, "Failed to register the application context event."); } using (ApplicationRunningContext context = new ApplicationRunningContext(clonedHandle)) { lock (s_applicationChangedEventLock) { if (state == Interop.ApplicationManager.AppContextEvent.Launched) { s_launchedHandler?.Invoke(null, new ApplicationLaunchedEventArgs { ApplicationRunningContext = context }); } else if (state == Interop.ApplicationManager.AppContextEvent.Terminated) { s_terminatedHandler?.Invoke(null, new ApplicationTerminatedEventArgs { ApplicationRunningContext = context }); } } } }; err = Interop.ApplicationManager.AppManagerSetAppContextEvent(s_applicationChangedEventCallback, IntPtr.Zero); if (err != Interop.ApplicationManager.ErrorCode.None) { throw ApplicationManagerErrorFactory.GetException(err, "Failed to register the application context event."); } }