有时候,我们需要用到返回键的功能,但为了美观,通常我们会将返回键放在页面左上角,这里我们就需要触发这个返回键的功能才能起到返回的作用,看代码吧
backBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new Thread() {
public void run() {
try {
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
} catch (Exception e) {
Log.e("Exception when sendKeyDownUpSync",
e.toString());
}
}
}.start();
}
});