I know this question is a bit old but I just started working on a UIAutomator project and figured I would share what I found.
The original question is a little ambiguous. It seems from the existing answers everyone assumed the question was about command line arguments/ startup arguments so I'm going to follow suit.
Neither of the answewrs worked well for what I was doing. The first can be used I think, but its a bit overkill to over ride onCreate for such a simple task. The second just didn't seem to work at all for me. I believe it is missing some information.
Get parameters is a call from the arguments Bundle. You need to get the from the instrumentation test. You can do that in AndroidTest by calling to InstrumentationRegistry
Bundle testBundle = InstrumentationRegistry.getArguments();
Then you can make the get string call from that bundle.
testBundle.getString(key);
I'm not sure how to do this exactly from eclipse or android studio, but from command line you can then specify running your test with the following ADB call.
adb shell am instrument -w -r -e debug false -e class com.example.testApp.testappone.ExampleClass -e ParamKey 'your variable value' com.example.testApp.testappone.test/android.support.test.runner.AndroidJUnitRunner
Just to show a full example, if you make the adb call above you would then access the parameter with the following code.
@Test
public void FirstTest(){
Bundle testBundle = InstrumentationRegistry.getArguments();
String paramValue = testBundle.getString("ParamKey");
}
I do want to note that you can make the adb call numerous ways so please don't get caught up in using instrument vs uiautomator. The important part is you specify the parameter with -e key value.
sources:
Android Junit runner - used to run UI automator projects
and
Instrumentation documentation