有没有办法从主屏幕在Android活动onResume区分?没有办法、屏幕、onResume、Android

2023-09-05 23:39:20 作者:巴黎彼岸°花开不败

有没有办法告诉一个活动是否正在恢复(即onResume被调用)从主屏幕/启动?

Is there any way to tell whether an Activity is being resumed (i.e. onResume is called) from the home screen/launcher?

例如,如果我有两个活动,A和B的应用

For example, if I have an Application with two activities, A and B.

情景1: 在活动答有些用户操作将调用b活动,把它推向前台 - 活动活动一到后台。作为一个活动移动到背景,它经历的onPause()和的onStop()。用户(现在活动B)或者完成活动或打后退按钮,将活动一回前台,引起onRestart(),ONSTART(),onResume()序列。

Scenario 1: Some user action on Activity A will invoke Activity B, bringing it into the foreground - moving Activity A into the background. As Activity A moves into the background, it goes through onPause() and onStop(). The user (now on Activity B) either finishes the Activity or hits the "back" button, bringing Activity A back to the foreground, causing an onRestart(), onStart(), onResume() sequence.

方案2: 如果用户点击主页按钮,而活动A是在前台,然后再调用从启动的应用程序,它通过了相同的生命周期在方案1即用户点击主页按钮。活动经过的onPause()和的onStop()。用户再次启动应用程序,使活动一展身手回来推向前台,再经历同样的onRestart(),ONSTART(),onResume()序列在方案1。

Scenario 2: If the user hits the "home" button while Activity A is in the foreground and then re-invokes the Application from the launcher, it goes through the same lifecycle as in Scenario 1. I.e. User hits the "home" button. Activity goes through onPause() and onStop(). User launches the application again, causing Activity A go come back into the foreground, again going through the same onRestart(), onStart(), onResume() sequence as in Scenario 1.

据我所知,该活动没有办法知道它是怎么恢复,它只是知道它是被带回到视图。其实,我有一种感觉,那是不是真的尽可能多的在Android中的应用程序的一个概念 - 在什么意义上,有一个单独的入口和出口点

As far as I can tell, the Activity has no way of knowing how it was resumed, it just knows it is being brought back into view. In fact, I have a feeling that there isn't really as much of a concept of an "Application" in Android - in the sense of something that has a single entry and exit point.

推荐答案

在方案2,你的活动将得到一个onNewIntent电话,与传递给它的发射意图。

in Scenario 2, your activity will get an onNewIntent call, with the launcher intent passed to it.

 
精彩推荐
图片推荐