Java – custom parameters / variables passed to the Android simulator

I want to pass a parameter to the Android simulator launched through eclipse This parameter is a custom parameter. I will use it to determine whether the connection address of the server is "localhost" or "myserverdomain. Com" This is because whenever I run a program in a production environment or a local test environment, I don't want two binaries or two versions of the same program

In normal Java, I can use command-line arguments and retrieve them in main (), or use custom environment variables and use system Getproperty () retrieves them

I can't find any similar features in Android You know what?

Solution

This is possible, although I haven't tried eclipse

From the command line, you can use ADB to start the a shell and run the application with parameters

For example,

adb shell am start -a android.intent.action.MAIN -n org.caoilte.MyActivity -e SOME_KEY some_value -e SOME_OTHER_KEY some_other_value

I will start my activity with additional content that I can extract from the package, so,

public class MyActivity extends Activity {

protected void onStart() {
    super.onStart();


    String someKey = null;
    String someOtherKey = null;

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        jsEnv = extras.getString("SOME_KEY");
        serverEnv = extras.getString("SOME_OTHER_KEY");
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>