Android Example Library (JAR) interface using inline Java code and "direct calling"

Discussion in 'Tutorials & Examples' started by Johan Schoeman, Feb 28, 2015.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Attached project demonstrates two ways to interface with a JAR file:

    1. Using the JavaObject run method "directly"
    2. Making use of inline Java code

    For method 1 you need to make use of
    #AdditionalJar: fiddleAround in the B4A code (see the code)

    For method 2 you need to make use of
    import com.johan.Geometry.Geometry; (see inline Java code)

    com.johan.Geometry is a package name within fiddleAround.Jar
    com.johan.Geometry.Geometry
    is a class within package com.johan.Geometry
    sphereVolume
    and sphereSurface are methods within class Geometry

    Project prints to the project log only.

    Amazing what you can see inside a JAR when using a Java decompiler
    It can make life much simpler when trying to use a/interface with a foreign JAR file.

    fiddleAround.jar and fiddleAround.xml that are used in this example are inside the /files folder of the attached project.
     

    Attached Files:

  2. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Ooooops - small error inside the code. The last bit of Sub Activity_Create should look like this:

    Code:
    'Now we are going to call the same methods making use of inline java code
        'This initialization needs to be here and not earlier in Sub Activity_Create
        jo.InitializeContext
        
    Dim e As Double = 4
        e = jo.RunMethod(
    "logVolume",Array(e))
        
    Log("ILJ sphereVolume = " & e)
       
        jo.InitializeContext
        e = 
    4
        e = jo.RunMethod(
    "logSurface",Array(e))
        
    Log("ILJ sphereSurface = " & e)
     
  3. Johan Schoeman

    Johan Schoeman Expert Licensed User

    By the way...something unique about using 3 as the radius when calculating the volume and the surface area of a sphere. Another interesting fact about spheres:

    The derivative of the volume (to R) yields the surface area....

    Volume = 4/3 PI R^3
    Surface Area = 4 PI R^2

    Interesting...
     
    JordiCP likes this.
  4. Johan Schoeman

    Johan Schoeman Expert Licensed User

    There is another way to interface with the fiddleAround library when fiddleAround is selected/enabled in the Libs tab of the project.

    Dim sur As B4Ageometry

    e = sur.sphereVolume(4.0)
    Log("Using Library --> sphereVolume = " & e)

    e = sur.sphereSurface(4.0)
    Log("Using Library --> sphereSurface = " & e)

    See additional code added to the attached project. Wow! B4A is flexible delux....!
     

    Attached Files:

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice