+redef class NativeActivity
+
+ private fun remove_title_bar in "Java" `{
+ self.requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
+ `}
+
+ # Insert a single layout as the root of the activity window
+ private fun insert_root_layout(root_layout_id: Int)
+ in "Java" `{
+ android.widget.FrameLayout layout = new android.widget.FrameLayout(self);
+ layout.setId((int)root_layout_id);
+ self.setContentView(layout);
+ `}
+
+ # Replace the currently visible fragment, if any, with `native_fragment`
+ private fun show_fragment(root_layout_id: Int, native_fragment: Android_app_Fragment)
+ in "Java" `{
+ android.app.FragmentTransaction transaction = self.getFragmentManager().beginTransaction();
+ transaction.replace((int)root_layout_id, native_fragment);
+ transaction.commit();
+ `}
+end
+
+redef class App
+ redef fun on_create
+ do
+ app.native_activity.remove_title_bar
+ native_activity.insert_root_layout(root_layout_id)
+ super
+ end
+
+ # Identifier of the container holding the fragments
+ private var root_layout_id = 0xFFFF
+
+ redef fun window=(window)
+ do
+ native_activity.show_fragment(root_layout_id, window.native)
+ super
+ end
+end
+
+redef class Activity
+ redef fun on_back_pressed
+ do
+ var window = app.window
+ if window.enable_back_button then
+ window.on_back_button
+ return true
+ end
+
+ return false
+ end
+end
+
+# On Android, a window is implemented with the fragment `native`