Android: Detect when another Activity is launched (or your activity loses focus)

前端 未结 3 658
鱼传尺愫
鱼传尺愫 2020-12-09 20:43

Like the title says, I need to detect when my app loses focus because another app is launched (Phone call comes in, or user hits Home etc).

Overriding Activity.OnSto

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 21:19

    AFAIK Android offers no facility for this. You may be able to track this yourself (e.g., if onStop() in one of your activities is called, and onStart() in another of your activities is not called within X period of time, presumably some other app's activity is in the foreground).

提交回复
热议问题