Environment variables are visible only in the process that sets the variable, and child processes start after setting the variable. When you set the environment variable from the adb shell, you are not in the parent process of the process that launches the Android application, so the application cannot see the variable you specified.
There is no System.setenv() in Java (and Android), but if you need to set an environment variable for your own program to read, there are always better ways. One of these methods is setting and getting properties .
Setting environment variables in Java is actually not possible (well, it is, but you do not want to do this). You can use ProcessBuilder if you want to set a variable that another process should read, but what if the process starts with a Java / Android program.
Think about what problem you are trying to solve, and if it can be done without using environment variables. They are not well suited for Java, but on Android they are even worse.
richq
source share