【问题标题】:Add Attribute stopWithTask="true" to <service /> in android manifest xamarin在 android manifest xamarin 中将属性 stopWithTask="true" 添加到 <service />
【发布时间】:2017-05-02 12:09:56
【问题描述】:

如果我的应用被向上滑动并关闭,我想清理资源并停止服务。在这种情况下,正常的onDestroy() LifeCycle 事件不会被触发。通过一点点搜索,我发现我需要重写onTaskRemoved(Intent rootIntent) 方法并将stopWithTask="true" 添加到清单中的服务中。

但是如何通过 Xamarin Visual Studio 将 &lt;service /&gt; 中的 stopWithTask="true" 属性添加到最终生成的清单中?上面指定的[Service] 属性 c# 类没有stopWithTask 属性。它们只有ExportedNameIsIsolatedIcon 属性。

【问题讨论】:

    标签: c# android .net xamarin xamarin.android


    【解决方案1】:

    我相信您可以在OnTaskRemoved() 方法中调用StopSelf(),这将有效地执行与android:stopWithTask="true" 相同的操作。

    遗憾的是,android:stopWithTask 项目没有得到很好的记录。如果您查看Service 的主要语法,您应该从顶部看到此项:

    https://developer.android.com/guide/topics/manifest/service-element.html

    但它几乎没有记录在 FLAG_STOP_WITH_TASK 项目中:

    https://developer.android.com/reference/android/content/pm/ServiceInfo.html#FLAG_STOP_WITH_TASK

    链接到:

    https://developer.android.com/reference/android/R.attr.html#stopWithTask

    我个人会使用第一种方法而不是这个属性,因为它在 Android 方面没有很好的记录。

    【讨论】:

      猜你喜欢
      • 2019-02-28
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      相关资源
      最近更新 更多