Loading AndroidHarnessFragment in android Activity?

Help me, in initializing AndroidHarnessFragment in activity, instead of defining in Activity layout?

1 Like

@DineshDAC well , this is pure android xml & java & not very much related to jme .

In the xml layout file , create a frameLayout tag(or any layout/cardView/RelativeLayout etc) with your own id inside your parent layout tag , it acts as a container or holder:

   <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible"
        android:background="@color/postLightBlack"
        />

then, use FragmentManager in your androidx.appcompat.app.AppCompatActivity
as follows :

package com.scrappers.dbtraining;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;

import com.scrappers.dbtraining.mainScreens.ioStreamScreen.IOStreamScreen;
import com.scrappers.dbtraining.navigation.Navigation;

import static com.scrappers.dbtraining.navigation.Navigation.drawerLayout;

public class HolderActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_holder);
        /*this holds your JmEFragmentHarness*/
        displayWindow(new IOStreamScreen());
    }
    private void displayWindow(@NonNull Fragment fragment){
        FragmentTransaction fragmentTransaction= getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.content,fragment);
        fragmentTransaction.commit();
    }
}

though , i have managed to make a new library that renders jmonkeyEngine in an android View , so you could use it in whatever you like , but currently there are still some bugs there.

Check this for this method :slight_smile: using FragmentManager ;
https://developer.android.com/guide/fragments/fragmentmanager

this is another way of adding a frag to the activity using Fragment tag:
https://developer.android.com/guide/fragments/create

EDIT : this would be an example for JmEHarness which is an actual Fragment holding the GLSurfaceView that holds the OGESContext which is an actual GLSurfaceView.Renderer Context :

XML of Layout container Tag :

and to call it :

the git repo of the 1st example , if you would like to take a closer look :

the xml container :

the fragment class( substitute this w/ jmeFragmentHarness ):

How to run inside android activity :

1 Like