2013年6月26日 星期三

foreground service trick

If you experiencing an issue that you cannot start a foreground service, you can look forward this article may help you.

Pre: 
According to Google doc, if you want to start a foreground service, you can call a function startForeground (int id, Notification notification) in your service.


Then your service will keep running even if your application/activities are destroyed.

Trick:
REMEMBER. DON'T use 0 as the input of int parameter, if you don't want to spend 2 days on fixing it.

startForeground(0, notification); // Doesn't work...

startForeground(1, notification); // Works!!!


P.S. Someone in the above post said he tried 123 which also doesn't work. Only 1 is work. I haven't prove it. If anyone tried, please tell me.



沒有留言:

張貼留言