在我的活動中,當用戶按下電源按鈕微調顯示成功時,我顯示微調,如果用戶選擇任何選項都可以正常工作,但是當用戶按回它所需的兩次後按以顯示原始活動我該怎麼辦?如何關閉並完成活動只是單個後退?需要兩次警報對話返回到完成活動
public class ActivityHome extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(KeyEvent.KEYCODE_POWER == event.getKeyCode() && isRooted()) {
startActivity(new Intent(ActivityHome.this, Spinnermenu.class));
return true;
}
return super.onKeyDown(keyCode, event);
}
public class Spinnermenu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
final String items[] = {"Power off","Restart"};
AlertDialog.Builder ab=new AlertDialog.Builder(Spinnermenu.this);
ab.setTitle("Power Options");
ab.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int choice) {
if(choice == 0) {
Toast.makeText(Spinnermenu.this,"PowerOff Perform",Toast.LENGTH_SHORT).show();
}
else if(choice == 1) {
}
});
ab.show();
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode==KeyEvent.KEYCODE_BACK){
this.finish();
}
return true;
}
}
在eclipse中嘗試CTRL + A然後按CTRL + I來修復代碼的縮進 – donfuxx
@SulthanAllaudeen請不要在「提前致謝」。發佈。 –
@Mikeyaworski是的,我會糾正自己。 –