本文介绍了光洁度()和System.exit之间差(0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我说的是在Android的程序。

在早期的日子里,我认为,完成()关闭当前的活动的并返回到previous在活动栈, System.exit(0)关闭整个应用程序的。

In early days I thought that, finish() closes current activity and go back to the previous in Activity stack, and System.exit(0) closes the whole application.

但我错了。我做了一个小实验,了解,双方将结束只有当前活动

But I was wrong.I made a small experiment and understood that Both will finish only the current Activity.

这是我能看到的唯一的区别是,在安卓2.3.3

The only differences that I could notice is that, in Android 2.3.3

  • ActivityResult 传播回 onActivityResult()使用完成()。而 onActivityResult()不要求 System.exit(0)
  • The ActivityResult is propagated back to onActivityResult() using finish(). Whereas onActivityResult() not called for System.exit(0).

但在Android的4.2.2,onActivityResult()被调用这两个!和意图是出境空()。(我在这两个设备只测试)

But in Android 4.2.2, onActivityResult() is called for both! and Intent was null for exit().(I tested only in these 2 devices)

  • 在这里使用的exit(),而完成()更快。(好像更多的后台操作是否有在退出的时候是一个时间滞后())
  • There is a time lag when using exit() whereas finish() is faster.(seems like more background operations are there in exit())

因此​​,

  1. 什么是两者之间的区别?

  1. what's the difference between two?

在哪些情况下,我可以使用退出()?

In which situations, I can use exit()?

我相信还有更多的东西是我的两种方法之间缺少研究。希望有人能解释更多指正。

I believe there is something more that I'm missing in between the two methods.Hope somebody can Explain more and correct me.

感谢

编辑致函索取:

请一个Android应用程序有2个活动。使用意图从启动活动调用次活动。现在,第二个活动里,在点击一个按钮,叫 System.exit(0)。的虚拟机停止进一步执行,程序将退出。的????(据documentation)

Make an Android application with 2 Activities. Call second Activity from Launcher activity using Intent. Now, inside the second activity, upon a button click, call System.exit(0);."The VM stops further execution and program will exit."????(according to documentation)

我看到第一个在那里的活动。为什么?(欢迎您来证明我错了/我是正确的)

I see first activity there. Why?(You are welcome to prove that I'm wrong/ I was right)

推荐答案

据Android开发 -

According to android Developer -

完成()

打电话当你的活动已经完成,应该关闭。该  ActivityResult传播回谁通过推出您  onActivityResult()。

System.exit(0)

虚拟机停止进一步执行,程序将退出。

这篇关于光洁度()和System.exit之间差(0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 11:29
查看更多