简体   繁体   English

OnDestroy被称为WearableListenerService

[英]OnDestroy being called WearableListenerService

I am implementing an service inherited from wearablelistenerservice. 我正在实现从wearablelistenerservice继承的服务。

Its weird that the onDestroy method being called with the service is still running. 奇怪的是,该服务调用的onDestroy方法仍在运行。 What should I do to avoid the ondestroy method being called? 我应该怎么做才能避免调用ondestroy方法?

thanks. 谢谢。

Are you deferring some work to the background thread after receiving a callback in WearableListenerService ? 您是否在WearableListenerService收到回调后将一些工作推迟到后台线程执行? If yes, as soon as you leave the callback method scope, the service is a fair game and will be destroyed as soon as system decides so. 如果是,则一旦离开回调方法范围,该服务就是一项公平的游戏,并且一旦系统决定立即将其销毁。 The only guarantee (sort of) you are getting in WearableListenerService is that it will be kept alive in the scope of the callback method (unless there is a very strong memory pressure). 您在WearableListenerService中获得的唯一保证是,它将在回调方法的范围内保持活动状态(除非存在很大的内存压力)。 If you need to do some background work, you start an IntentService from the WearableListenerService . 如果需要进行一些后台工作,则可以从WearableListenerService启动IntentService However, it might be not necessary. 但是,可能没有必要。 WearableListenerService callback is already on a background thread, so you can do all the work you want. WearableListenerService回调已经在后台线程上,因此您可以完成所有需要的工作。 Just don't leave the method scope (no waiting for callbacks or launching AsynTask s; stick to blocking calls). 只是不要离开方法范围(不要等待回调或启动AsynTask ;不要阻塞调用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM