FileDocCategorySizeDatePackage
ContactsSelectInstrumentation.javaAPI DocGoogle Android v1.5 Example3248Sun Nov 11 13:01:04 GMT 2007com.google.android.samples.app

ContactsSelectInstrumentation

public class ContactsSelectInstrumentation extends android.app.Instrumentation
This is an example implementation of the {@link android.app.Instrumentation} class, allowing you to run tests against application code. The instrumentation implementation here is loaded into the application's process, for controlling and monitoring what it does.

Fields Summary
Constructors Summary
Methods Summary
public voidonCreate(android.os.Bundle arguments)

        super.onCreate(arguments);

        // When this instrumentation is created, we simply want to start
        // its test code off in a separate thread, which will call back
        // to us in onStart().
        start();
    
public voidonStart()

        // First start the activity we are instrumenting -- the contacts
        // list.
        Intent intent = new Intent(Intent.MAIN_ACTION);
        intent.setClassName(getTargetContext(),
                "com.google.android.contacts.ContactsList");
        Activity activity = startActivitySync(intent);

        // This is the Activity object that was started, to do with as we want.
        Log.i("ContactsSelectInstrumentation", "Started: " + activity);

        // Monitor for the expected start activity call.
        ActivityMonitor am = addMonitor(IntentFilter.create(
            Intent.VIEW_ACTION, Contacts.People.CONTENT_ITEM_TYPE), null, true);

        // We are going to enqueue a couple key events to simulate the user
        // selecting an item in the list.
        sendKeySync(new KeyEvent(
            KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN));
        sendKeySync(new KeyEvent(
            KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_DOWN));
        sendKeySync(new KeyEvent(
            KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
        sendKeySync(new KeyEvent(
            KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));

        // Was the expected activity started?
        if (checkMonitorHit(am, 1)) {
            Log.i("ContactsSelectInstrumentation", "Activity started!");
        } else {
            Log.i("ContactsSelectInstrumentation", "*** ACTIVITY NOT STARTED!");
        }

        // And we are done!
        Log.i("ContactsSelectInstrumentation", "Done!");
        finish(Activity.RESULT_OK, null);