Java Question [solved] android.content.Context in B4A ?

MarkusR

Well-Known Member
Licensed User
Longtime User
i need help
for my android lib i need init my class in b4a with a android.content.Context
because GLSurfaceView have this in the constructor.

android library part in android studio
B4X:
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.View;

@ShortName("ThreeDimensional")
public class ThreeDimensional {

    private GLSurfaceView glView;                   // use GLSurfaceView

    public View Init(Context context)
    {
        glView = new GLSurfaceView(context);           // Allocate a GLSurfaceView
        glView.setRenderer(new MyGLRenderer(context)); // Use a custom renderer

        return glView;
    }

b4a
B4X:
Private Test1 As ThreeDimensional
Test1.Init(???)
 

MarkusR

Well-Known Member
Licensed User
Longtime User
ok, i used it here because my app is b4a and related to android sdk.

what i found yet:
Context is the base class for Activity, Service, Application .... etc
..
Different invoking methods by which you can get context

getApplicationContext()
getContext()
getBaseContext()
or this (when in the activity class)
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
I guess 95-98% of the Java-Questions are related to B4A and Android.

Additionally your question IS about a Library for B4A (you are creating a java-Library for b4a) so it should be placed in the Developer Questionsforum
https://www.b4x.com/android/forum/forums/libraries-developers-questions.32/
The Name of this subforumn is
Libraries developers questions
Your question is not a question related to this forum?

Also note that the Forum is a subforum of the B4A Questionsforum.
 

MarkusR

Well-Known Member
Licensed User
Longtime User
Libraries developers questions
saw this sub forum first time lol
my library compile well. currently i am in b4a activity and will use the functionality.

...

i have plan B
i change the function input to activity and get the context in the library:
B4X:
 public View Init2(Activity activity)
    {
        Context context = activity.getBaseContext();

wahhh, Activity in B4A is BALayout !?
Three.Init2(Activity)
src\com\rauch\opengl\main.java:380: error: incompatible types: BALayout cannot be converted to Activity
_three.Init2((Activity)(mostCurrent._activity.getObject()));

i need to give android.content.Context or android.app.Activity to my library.
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
ba.contex

ba.context and ba.activity
 

MarkusR

Well-Known Member
Licensed User
Longtime User
what is ba. ? what lib does it comes from?
i not using any b4a system related libs in my android studio library project.
this ba.context i need in b4a project compatible/equal with android.content.Context
 

OliverA

Expert
Licensed User
Longtime User

MarkusR

Well-Known Member
Licensed User
Longtime User
that GetContext did not work but in the link i found the key!!! thank you all very much. now i have a working 3d lib in b4a

need reflection lib 2.40
B4X:
Sub GetActivity As Object
    Dim R  As Reflector
    Return R.GetActivity
End Sub



 
Last edited:

Informatix

Expert
Licensed User
Longtime User
what is ba. ? what lib does it comes from?
i not using any b4a system related libs in my android studio library project.
this ba.context i need in b4a project compatible/equal with android.content.Context

public View Init(Context context)
should be
public View Init(BA ba)

The ba parameter won't be visible for the B4A user but it will be automatically filled when the function is called, allowing to get the context or the activity, and to raise B4A events.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…