Android方法中断

时间:2013-06-06 13:37:14

标签: android

如果我在UI线程中执行了一个方法,这个方法总是会一直运行到最后,或者这个方法可以在中间某处被中断(通过任何将你的活动发送到暂停状态的东西)?

谢谢!

3 个答案:

答案 0 :(得分:1)

您的方法将因崩溃而中断(例如,未处理的例外)。

任何将您的活动发送到暂停状态的内容都不会中断。

答案 1 :(得分:0)

如果您在代码中放置了一些明确的sleep(),那么这可以将整个UI锁定几秒钟。你不能pause a process in android or Java,你最多只能sleep threads.

答案 2 :(得分:-1)

如果要退出中间的方法调用,请使用“return”关键字。例如:

public void doLengthyCalculation(){
  boolean notRequired = true;
  //Do something...
  //Do something else...
  //Now we need to exit
  if(notRequired == true){
    return; //Anything after this point will not be executed.
  }
  //Some more code which will not be executed if above if statement evaluates to true
}

希望它有用。

相关问题