简体   繁体   English

没有调用onPause的整理活动

[英]Finishing activity without onPause called

I am finishing my current activity using finish(). 我正在使用finish()完成当前活动。 This is calling onPause automatically. 这是自动调用onPause。 I want to finish activity without onPause being called. 我想完成活动而不调用onPause。 My activity is running a song service so i want song to stop when app is in background but dont want it to stop when user goes from one activity into another in my app. 我的活动正在运行歌曲服务,因此我希望在应用程序处于后台时停止播放歌曲,但是当用户从我的应用程序中的一项活动转到另一项活动时不希望停止播放。 I cant do stopService and startService in between activities because then there is a momentary lag in between the sounds. 我不能在活动之间进行stopService和startService,因为在声音之间会有短暂的滞后。

A Service is an application component that can perform long-running operations in the background and does not provide a user interface 服务是可以在后台执行长时间运行的操作且不提供用户界面的应用程序组件

google docs 谷歌文档

The background Service is agnostic of which Activity is running or any discontinuity between them. 后台Service无法确定正在运行哪个Activity或它们之间是否存在任何中断。

The two types, "bound" and "started" are supposed to have different persistence characteristics but in practice (not stress testing) I find the bound Service does not clobbered for lack of system memory and is much easier to implement (despite tutorials claiming otherwise). 两种类型的“绑定”和“开始”应该具有不同的持久性特征,但是在实践中(不是压力测试),我发现绑定Service不会因缺乏系统内存而瘫痪,并且易于实现(尽管教程声称不是这样) )。 It uses some IPC abstraction that appears as though it is being directly invoked from the Activity . 它使用一些IPC抽象,看起来好像是直接从Activity调用它一样。 The same can't be said of the "started" variety (unless it is also bound) which is IMO a closer approximation to the traditional service I would associate with web-servers (or anything that is already going to be experiencing not insignificant delays- such as due to network transmission). 不能说“开始”的版本(除非它也受约束),这是IMO与我将与Web服务器关联的传统服务(或任何已经经历了不小的延迟)的更接近的近似值-例如由于网络传输)。

(Lecture over) I see you are calling finish() . (讲座结束)我看到您正在调用finish() You need some way to shut down the Service from your Activity . 您需要某种方法从Activity关闭Service Just make sure to branch aways from doing so when not intended. 只要确保在不希望这样做时就不要这样做。 Code would be helpful but I can assure you this is how media players work. 代码会有所帮助,但我可以向您保证,这是媒体播放器的工作方式。

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

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