這聽起來像一個前臺服務正是你所需要的。當您創建它時,會在狀態欄中放置一條通知,告訴用戶它正在運行。該服務也被賦予高優先級,以便它不會被取消。
從對前景標記的文檔:
public final void startForeground (int id, Notification notification)
Make this service run in the foreground, supplying the ongoing notification
to be shown to the user while in this state. By default services are background,
meaning that if the system needs to kill them to reclaim more memory (such as to
display a large page in a web browser), they can be killed without too much harm.
You can set this flag if killing your service would be disruptive to the user,
such as if your service is performing background music playback, so the user
would notice if their music stopped playing.
你可以看一下文檔here的其餘部分。
好的,謝謝你的回答,我要檢查一下,然後接受答案,一旦我玩你提到的一點點 – user577732