super.onStart();
// First start the activity we are instrumenting -- the save/restore
// state sample, which has a nice edit text into which we can write
// text.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(getTargetContext(), SaveRestoreState.class);
SaveRestoreState activity = (SaveRestoreState)startActivitySync(intent);
// This is the Activity object that was started, to do with as we want.
Log.i("LocalSampleInstrumentation",
"Initial text: " + activity.getSavedText());
// Clear the text so we start fresh.
runOnMainSync(new ActivityRunnable(activity) {
public void run() {
((SaveRestoreState)activity).setSavedText("");
}
});
// Act like the user is typing some text.
sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT));
sendCharacterSync(KeyEvent.KEYCODE_H);
sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT));
sendCharacterSync(KeyEvent.KEYCODE_E);
sendCharacterSync(KeyEvent.KEYCODE_L);
sendCharacterSync(KeyEvent.KEYCODE_L);
sendCharacterSync(KeyEvent.KEYCODE_O);
// Wait for the activity to finish all of its processing.
waitForIdleSync();
// Retrieve the text we should have written...
Log.i("LocalSampleInstrumentation",
"Final text: " + activity.getSavedText());
// And we are done!
Log.i("ContactsFilterInstrumentation", "Done!");
finish(Activity.RESULT_OK, null);