[英]What happens when we call finish() in onCreate() method?
What happens when we call the finish()
method for the activity inside onCreate()
?当我们为onCreate()
中的活动调用finish()
方法时会发生什么? Will the app get time to display the Activity
, but then rapidly close, or won't it show anything?该应用程序是否有时间显示Activity
,但随后迅速关闭,或者它不会显示任何内容? This is just a doubt that I had before reading about some malware services for android that allegedly use this idea... Does it effectively work?这只是我在阅读一些据称使用这个想法的 android 恶意软件服务之前的疑问......它有效吗?
I just tested and debugged it, the Activity
starts but is immediately closes once the event is generated.我刚刚对其进行了测试和调试, Activity
启动但在事件生成后立即关闭。
As MrMins mention it will rapidly close.正如 MrMins 提到的那样,它将迅速关闭。 The lifecycle will skip over some important steps, therefore causing potential issues.生命周期会跳过一些重要的步骤,从而导致潜在的问题。
But to answer you question it will run only momentarily.但要回答你的问题,它只会暂时运行。
Here is the android documentation of the lifecycle: https://developer.android.com/guide/components/activities/activity-lifecycle.html这是生命周期的 android 文档: https://developer.android.com/guide/components/activities/activity-lifecycle.html
As per official documentation : 根据官方文件:
You can call finish() from within this function, in which case onDestroy() will be immediately called after onCreate(Bundle) without any of the rest of the activity lifecycle (onStart(), onResume(), onPause(), etc) executing.您可以从这个 function 中调用 finish(),在这种情况下,onDestroy() 将在 onCreate(Bundle) 之后立即被调用,而没有任何活动生命周期的 rest(onStart()、onResume()、onPause() 等)执行。
The visible lifetime of an activity happens between a call to onStart() until a corresponding call to onStop().活动的可见生命周期发生在对 onStart() 的调用与对 onStop() 的相应调用之间。
so the "visible lifetime" is not reached for that case.所以这种情况下没有达到“可见寿命”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.