最終更新:2021-12-06 (月) 22:59:14 (870d)  

Android/フォアグラウンドサービス
Top / Android / フォアグラウンドサービス

フォアグラウンド実行

  • フォアグラウンドのサービスは、ユーザが積極的に意識するものとして考えられ、それゆえにメモリ残量が少なくなった際のシステムによる強制終了の候補にはなりません
  • フォアグラウンドのサービスはステータスバーに通知を提供する必要があり、サービスは "継続中" にあるという位置付けになり、これはサービスが停止されるかフォアグラウンドから除去されない限りは、通知を片付けることができないということを意味します。

メモ

  • A started service can use the startForeground(int, Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory. (It is still theoretically possible for the service to be killed under extreme memory pressure from the current foreground application, but in practice this should not be a concern.)

使い方

  • Service.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.

関連