Java Question Start initialized activity from library

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hi,

I want to start an activity that has been initialized in Basic4Android but where the activity is in the library.

I'm doing the following:
B4X:
public void Initialize(final BA ba, String EventName, Camera camera, EngineOptions engineOptions) {
      this.ba = ba;
      this.eventName = EventName;
      this.camera = camera;
       this.engineOptions = engineOptions;

   }

and after initialize
B4X:
   public Intent Load(BA pBA){
        Intent intent1 = new Intent(pBA.context, RSSimpleBaseGameActivity.class);
        return intent1;
    }

This works, and this gets called:
B4X:
@Override
   public EngineOptions onCreateEngineOptions() {
      // TODO Auto-generated method stub
      if (ba.subExists(eventName + "_createengineoptions")==true) {
         ba.raiseEvent(this, eventName + "_createengineoptions", new Object[] { this.engineOptions });
      }
      return engineOptions;
   }

However, with a NPE. This is because Load constructs a new Activity, so initialize is not called. I'm looking for a way that I can Initialize the class which was initialized before with the parameters, and so the EngineOptions doesn't throw a NPE, and works with the used arguments.

To conclude what i'm trying to do is extend the b4a activity instance - not create an entirely new instance of a different activity class.
So we can achieve the following

B4X:
'To start, we first have to initialize the camera and the options
   'before creating our game activity.
   mCamera.Initialize(0, 0, 854, 480)
   mOptions.Initialize(True, True, mOptions.LANDSCAPE_FIXED, mCamera)
   
   'Now we create our SimpleBaseGame Activity.
   SimpleBaseGameActivity.Initialize("Game", mCamera, mOptions)
   
   'We are ready to display our activity. 3 Methods will be called when constructing the activity.
   'We extract an intent from the activity and use StartActivity to start it.
   'Make sure to check the manifest!
   StartActivity(SimpleBaseGameActivity) ' LIke this

Regards,
Tomas
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Just to update this thread...

I took at look at this for XverhelstX and the real problem is that the 3rd party game SDK he wants to use extends the Activity class and he wants to use this Activity sub-class instead of the B4A Activity/ActivityWrapper class.

Reminds me of when i was trying to create a MapActivity within B4A - i never succeeded.

XverhelstX is going to investigate whether the game SDK can be used within a Fragment and that Fragment can be used with a standard B4A Activity.
I'm guessing that as the new Google Maps Android v2 library uses Fragments to add a MapView to a B4A Activity then so a different Fragment could (in theory) be added to a B4A Activity?

Martin.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm guessing that as the new Google Maps Android v2 library uses Fragments to add a MapView to a B4A Activity then so a different Fragment could (in theory) be added to a B4A Activity?
That is correct.

Your only option to work with special subclasses of Activity is by creating the complete Activity in your library (like is done in PreferenceActivity library).
 
Top