Checking if an Android application is running in the background

前端 未结 30 2900
无人共我
无人共我 2020-11-21 06:19

By background, I mean none of the application\'s activities are currently visible to the user?

30条回答
  •  忘掉有多难
    2020-11-21 06:53

    Offical docs:

    The system distinguishes between foreground and background apps. (The definition of background for purposes of service limitations is distinct from the definition used by memory management; an app might be in the background as pertains to memory management, but in the foreground as pertains to its ability to launch services.) An app is considered to be in the foreground if any of the following is true:

    1. It has a visible activity, whether the activity is started or paused.
    2. It has a foreground service.
    3. Another foreground app is connected to the app, either by binding to one of its services or by making use of one of its content providers. For example, the app is in the foreground if another app binds to its:
      • IME
      • Wallpaper service
      • Notification listener
      • Voice or text service

    If none of those conditions is true, the app is considered to be in the background.

提交回复
热议问题