[英]How to bring an android service into foreground or prevent it from being automatically stopped otherwise, without using intentservice?
I have a service with graphic elements, that needs to run for a few seconds then stops itself (all while the app itself is in background). 我有一个带有图形元素的服务,需要运行几秒钟然后停止运行(所有应用程序本身都在后台运行)。 But often times the system automatically closes the service due to low RAM.
但是通常由于内存不足,系统会自动关闭服务。
I am new to android, and all the codes for bringing service in foreground are using IntentServices. 我是android的新手,并且将服务引入前台的所有代码都使用IntentServices。
Can only IntentServices be brought to foreground? 只能将IntentServices带到前台吗? If yes, how can I prevent my service from closing.
如果是,如何防止我的服务关闭。
See [ startForeground()
]( http://developer.android.com/reference/android/app/Service.html#startForeground(int , android.app.Notification)) method of Service
class. 请参见
Service
类的[ startForeground()
]( http://developer.android.com/reference/android/app/Service.html#startForeground startForeground()
,android.app.Notification))方法。 Do note that it requires you to provide a Notification
. 请注意,这需要您提供“
Notification
。
I have a service with graphic elements
我有带有图形元素的服务
What exactly does that mean? 这到底是什么意思呢? A
Service
in Android is meant for the exact opposite use case - ie, when there is no user interaction desired. Android中的
Service
是针对完全相反的用例-即,当不需要用户交互时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.