Vah*_*yan 4 android recreate android-activity
我有一个 android studio 项目。当我旋转屏幕时,android 会破坏并重新创建主要活动。如果android要重新创建活动,我如何在销毁过程中检查?
您可以使用isFinishing()in确定活动是否通过用户选择完成(例如,用户选择按返回退出)onDestroy。
@Override
protected void onDestroy() {
super.onDestroy();
if (isFinishing()) {
// wrap stuff up
} else {
//It's an orientation change.
}
}
Run Code Online (Sandbox Code Playgroud)
另一种选择(如果您只针对 API>=11)是isChangingConfigurations.
@Override
protected void onDestroy() {
super.onDestroy();
if (isChangingConfigurations()) {
//It's an orientation change.
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1720 次 |
| 最近记录: |