mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
app/internal/window: [Android] replace RegisterFragment with Do
Do is a function for accessing the underlying Android View in a safe context, the main thread. Do is - more general than RegisterFragment and may be expanded to other platforms - simpler to implement (from the Gio side) and as a bonus, the Do implementation avoids a race condition where a call to RegisterFragment during an Activity re-create would be ignored. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -191,31 +191,6 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
|
||||
return onBack(nhandle);
|
||||
}
|
||||
|
||||
void registerFragment(String del) {
|
||||
final Class cls;
|
||||
try {
|
||||
cls = getContext().getClassLoader().loadClass(del);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("RegisterFragment: fragment class not found: " + e.getMessage());
|
||||
}
|
||||
|
||||
final Fragment frag;
|
||||
try {
|
||||
frag = (Fragment)cls.newInstance();
|
||||
} catch (IllegalAccessException | InstantiationException | ExceptionInInitializerError | SecurityException | ClassCastException e) {
|
||||
throw new RuntimeException("RegisterFragment: error instantiating fragment: " + e.getMessage());
|
||||
}
|
||||
final FragmentManager fm;
|
||||
try {
|
||||
fm = ((Activity)getContext()).getFragmentManager();
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException("RegisterFragment: cannot get fragment manager from View Context: " + e.getMessage());
|
||||
}
|
||||
FragmentTransaction ft = fm.beginTransaction();
|
||||
ft.add(frag, del);
|
||||
ft.commitNow();
|
||||
}
|
||||
|
||||
static private native long onCreateView(GioView view);
|
||||
static private native void onDestroyView(long handle);
|
||||
static private native void onStartView(long handle);
|
||||
|
||||
Reference in New Issue
Block a user