mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #109764 from ydeltastar/android-fragment-fix
Android: Ensure proper cleanup of the fragment
This commit is contained in:
commit
ef4863ab97
2 changed files with 25 additions and 1 deletions
|
@ -98,7 +98,16 @@ abstract class GodotActivity : FragmentActivity(), GodotHost {
|
||||||
} else {
|
} else {
|
||||||
Log.v(TAG, "Creating new Godot fragment instance.")
|
Log.v(TAG, "Creating new Godot fragment instance.")
|
||||||
godotFragment = initGodotInstance()
|
godotFragment = initGodotInstance()
|
||||||
supportFragmentManager.beginTransaction().replace(R.id.godot_fragment_container, godotFragment!!).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss()
|
|
||||||
|
val transaction = supportFragmentManager.beginTransaction()
|
||||||
|
if (currentFragment != null) {
|
||||||
|
Log.v(TAG, "Removing existing fragment before replacement.")
|
||||||
|
transaction.remove(currentFragment)
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.replace(R.id.godot_fragment_container, godotFragment!!)
|
||||||
|
.setPrimaryNavigationFragment(godotFragment)
|
||||||
|
.commitNowAllowingStateLoss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,11 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
|
if (godotContainerLayout != null && godotContainerLayout.getParent() != null) {
|
||||||
|
Log.d(TAG, "Cleaning up Godot container layout during detach.");
|
||||||
|
((ViewGroup)godotContainerLayout.getParent()).removeView(godotContainerLayout);
|
||||||
|
}
|
||||||
|
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
parentHost = null;
|
parentHost = null;
|
||||||
}
|
}
|
||||||
|
@ -233,11 +238,21 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
|
||||||
return downloadingExpansionView;
|
return downloadingExpansionView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (godotContainerLayout != null && godotContainerLayout.getParent() != null) {
|
||||||
|
Log.w(TAG, "Godot container layout already has a parent, removing it.");
|
||||||
|
((ViewGroup)godotContainerLayout.getParent()).removeView(godotContainerLayout);
|
||||||
|
}
|
||||||
|
|
||||||
return godotContainerLayout;
|
return godotContainerLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
if (godotContainerLayout != null && godotContainerLayout.getParent() != null) {
|
||||||
|
Log.w(TAG, "Removing Godot container layout from parent during destruction.");
|
||||||
|
((ViewGroup)godotContainerLayout.getParent()).removeView(godotContainerLayout);
|
||||||
|
}
|
||||||
|
|
||||||
godot.onDestroy(this);
|
godot.onDestroy(this);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue