0

I have access to the full logcat/DDMS output of an app in operation, as well as the source code.

If I see something like (taken from OpenSudoku)

03-11 20:38:28.110: I/ActivityManager(175): Starting: Intent { cmp=cz.romario.opensudoku/.gui.SudokuListActivity (has extras) } from pid 20367

how can I find out (from the intent information) what launched that particular intent. I understand that the cmp= tells which activity was launched, and from that information I can find the java source file of that particular activity, but I want to find in the (I think) layout which button or action made the call to that activity, and therefore created the intent.

It should be noted that I have the ability to see when a particular button is pressed, but I want to be able to confirm that this intent is related to said button press.

Rowhawn
  • 1,409
  • 1
  • 16
  • 25

1 Answers1

1

Here's an idea to get you started. Pass the Intent that launches SubActivity an, telling it which Button launched it.

final Intent intent = new Intent(BaseActivity.this, SubActivity.class);
intent.putExtra("LaunchingButton", R.id.button1);
startActivity(intent);

Retrieve the information in your launched activity's onCreate method:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sub_activity_layout);

    Intent data = getIntent();
    int from = data.getExtras().getInt("LaunchingButton");

    switch (from) {
    case R.id.button1: 
        /* button1 launched the Activity */
        break;
    }
}

In other words, you could pass the id of the Button being pressed to the Intent, and then in the launched activity, retrieve this information and switch-case over the possible View ids that could have started that particular activity.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
  • 1
    Thanks, this is a great idea! Unfortunately, I don't think I will have the ability to modify the source of the application I'm running. This is meant to be a component of a final product that will test applications in their unmodified state. – Rowhawn Mar 12 '12 at 01:17
  • Hmm... I'm a little unclear on what exactly it is you are trying to do now. The question you asked never says anything about analyzing some pre-existing app... is this what you are trying to do? – Alex Lockwood Mar 12 '12 at 01:51
  • Yes, my project is an extension to the Android GUITAR software https://sourceforge.net/apps/mediawiki/guitar/index.php?title=Android_Guitar which aims to test the GUIs of Android apps. The project is to implement a way to track the intents which are created during GUI interaction. – Rowhawn Mar 12 '12 at 01:59