有什么方法可以 prevent/protect 方法在配置更改期间不中断吗?

Is there any way to prevent/protect a method from breaking during a configuration change?

说:

public class MainActivity extends AppCompatActivity {

  ...

  public void doingSomething() {
  ...
  ...
  //the configuration change occurs here
  ...
  ...
  }

...

}

我需要防止上述方法因配置更改而中断。

当发生配置更改时,它会通过调用 onConfigurationChanged() 传递给您的 Activity(如果您告诉 Android 您想要自己处理配置更改)或者在默认情况下调用 onPause(), onStop()onDestroy(),其中 Android 杀死 Activity 并重新创建它。在所有这些情况下,调用都是在主 (UI) 线程上进行的。如果您在主 (UI) 线程上有一个方法 运行,则在您的方法完成之前无法进行这些调用。