10

I would like, for multiple testing purposes, start my android activity from Eclipse with specific data on the intent (e.g. extra data like a file name to load). Where in the menus can I provide this?

  • In the run configuration, there are nothing in the 3 tabs to provide any arguments
  • I could change some parameters in the resources files but I am afraid I might leak resources which will go to the final application.
  • It is possible to do it in adb: See here but it is not currently associatable with the F11 launch command in Eclipse that is useful for recompiling and relaunching at the same time.
Community
  • 1
  • 1
Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
  • Could you give more details about what you wanna? – Idemax Jul 09 '14 at 15:06
  • I guess there are no visual support (wizard) to do it. I looked for it now too but I can't find out. – Idemax Jul 09 '14 at 15:18
  • I just want to press F11 and see my application launched with special data in the intent. Because I am sharing this project with others people, I do not want to add this data directly in the project itself. – Mikaël Mayer Jul 09 '14 at 16:08
  • Understood so I figure out that is no way by some wizard of Eclipse. You could simulate it internally in your `Activity` where you getting `Intent` by `getIntent()` and extras by `getExtras()`. – Idemax Jul 09 '14 at 22:16
  • Also the answer of @Aegis is the best for now. – Idemax Jul 09 '14 at 22:16
  • For now... 23h left if someone finds a better solution or more detailed. – Mikaël Mayer Jul 15 '14 at 15:41

1 Answers1

7

If your still using eclipse you probably need need to create a simple ant script with a custom task to execute the test. ADB shell has a command to start activities where you can also specify extra's

am [start|instrument]

am start [-a <action>] [-d ]
[-t <mime_type>] [-c <category> [-c <category>] ...]
[-e <extra_key> <extra_value>
[-e <extra_key> <extra_value> ...]
[-n <component>] [-D] [<uri>]

am instrument [-e <arg_name> <arg_value>] [-p <prof_file>] [-w] <component>

You would pass them like this:

am start -a android.intent.action.VIEW -c android.intent.category.DEFAULT -e foo bar -e bert ernie -n org.package.name/.MyCustomActivity

P.S. don't forget the dot before the activity.

This can be translated to an ant target which you should put in the ant script.

<target name="run">
    <exec executable="adb">
        <arg value="shell"/>
        <arg value="am"/>
        <arg value="start"/>
        <arg value="-a"/>
        <arg value="android.intent.action.MAIN"/>
        <arg value="-e"/>
        <arg value="extra_key extra_value"/>
        <arg value="-n"/>
        <arg value="{package.name}/{activity}"/>
    </exec>
</target>

which you can execute like this: ant debug install run

How to run ant files from eclipse see:

Aegis
  • 5,761
  • 2
  • 33
  • 42