Java Question use on java a main process global variable

abilio486software

Active Member
Licensed User
Simplest way is to pass it as a method parameter.

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:

B4X:
Dim terminal_present as int

In my second activity, inside java create:

B4X:
#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:

abilio486software

Active Member
Licensed User
Yes, however mostCurrent is not needed.

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..." ?
 

abilio486software

Active 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.

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:
B4X:
public void _onCreate() {

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


But with obfuscation, I got this error:
B4X:
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?
 

abilio486software

Active 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.

B4X:
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!
 
Top