Java Question use on java a main process global variable

Discussion in 'Libraries developers questions' started by abilio486software, Jul 17, 2019.

  1. abilio486software

    abilio486software Member Licensed User

    How can I use an int variable, defined on main process globals, from an inline java routine?

    Thanks,
    Abilio
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Simplest way is to pass it as a method parameter.
     
    abilio486software likes this.
  3. abilio486software

    abilio486software Member Licensed User

    Thanks, I need to do include code on _On_Create, on a second activity, depending from a main Process Global variable "terminal_present".

    Can I use safety this from inline Java?

    In Process globals:

    Code:
    Dim terminal_present as int
    In my second activity, inside java create:

    Code:
    #If JAVA

    public void _onCreate() {
       requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

       if(mostCurrent._main._terminal_present) {

          // try to reconnect
        mostCurrent._main._terminal_present++;

      }
    }
    #End If
    Can I do this?
     
    Last edited: Jul 18, 2019
  4. Erel

    Erel Administrator Staff Member Licensed User

    Yes, however mostCurrent is not needed.
     
    abilio486software likes this.
  5. abilio486software

    abilio486software Member Licensed User

    Great! many thanks :D
     
  6. abilio486software

    abilio486software Member Licensed User

    It seems that obfuscation does not convert inline Java variable names if I reference a variable that is obfuscated during the compilation process.

    How can I use those variables? Can obfuscation replace "mostCurrent._main._terminal_present" with the new "something._vvvvvvvv..." ?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    The compiler doesn't know anything about your Java code.

    The variable was not obfuscated because it has an underscore in its name. It is good that it wasn't obfuscated as your Java code would have failed if it was obfuscated.
     
    abilio486software likes this.
  8. abilio486software

    abilio486software Member Licensed User

    Dear Erel,

    The problem is that I'm trying to use a variable from main Activity, in another activity.

    When I compile with obfuscation, the name of the activity changes.

    This code works fine without obfuscation:
    Code:
    public void _onCreate() {

      
        
    if(this._main._terminal_mypos_presente==1) {
      
              
            requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    But with obfuscation, I got this error:
    Code:
    B4A Version: 9.30
    Java Version: 
    8
    Parsing code.    (
    4.93s)
    Building folders structure.    (
    0.31s)
    Compiling code.    (
    4.39s)
      
    ObfuscatorMap.txt 
    file created in Objects folder.
    Compiling layouts code.    (
    0.02s)
    Organizing libraries.    (
    0.13s)
        (AndroidX SDK)
    Generating R 
    file.    (0.03s)
    Compiling generated Java code.    Error
    javac 
    1.8.0_181
    src\com\invoice\activity_faturar.java:
    11022: error: cannot find symbol
        
    if(this._main._terminal_mypos_presente==1) {
               ^
      symbol: variable _main
    Note: Some input files use 
    or override a deprecated API.
    Note: Recompile with -Xlint:deprecation 
    for details.
    1 error
    I also try without "this." but don't compile.

    How can I obfuscate and use the main variable?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    The activity name doesn't change.

    If I remember correctly the variable should be static so you should be able to access it with _main._terminstal_mypos_present.
     
    abilio486software likes this.
  10. abilio486software

    abilio486software Member Licensed User

    Exactly Erel. I added a module and its global variables are static, so I can use them inside inline java even with obfuscation.

    Code:
    if(_modulo_main._terminal_mypos_presente==1) {
    It's fantastic to use an external SDK directly from inline Java without the need of create a library.

    Many thanks.

    Solved!
     
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