Press "Back" on key board - Android User Interface

Android examples for User Interface:Key Event

Description

Press "Back" on key board

Demo Code

// Copyright 2012 The Chromium Authors. All rights reserved.
//package com.java2s;
import android.app.Instrumentation;
import android.view.KeyEvent;

public class Main {
    /**/* w w w.  j  a v  a  2  s .  c o m*/
     * Press "Back".
     */
    public static void pressBack(Instrumentation instrumentation) {
        instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN,
                KeyEvent.KEYCODE_BACK));
        instrumentation.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP,
                KeyEvent.KEYCODE_BACK));
        instrumentation.waitForIdleSync();
    }
}

Related Tutorials