2010-07-28 283 views
2

在我的應用程序中,我有兩個屏幕。 Screen1和Screen2。如果我在screen2時點擊後退按鈕,它將顯示screen1。我需要在點擊屏幕上的返回按鈕時關閉應用程序2。這個怎麼做???不要去android的前一個屏幕?

回答

5

也許你通過Intent從screen1開始screen2。

在您致電startActivity(screen2)後,您應該通過撥打finish()來關閉screen1。

喜歡的東西:

Intent screen2=new Intent(Screen1.this,Screen2.class); 
startActivity(screen2); 
finish(); 
+0

我使用此代碼來調用畫面2。如何完成第一屏是這兒過得新至Android所以請...Intent i = new Intent(screen1.this,screen2.class); startActivity(i); – RMK 2010-07-28 09:59:25

+0

我修改了我的問題 – Pentium10 2010-07-28 10:00:53

+0

謝謝你的幫助。它的工作 – RMK 2010-07-28 10:29:09

0

http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { 
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR 
     && keyCode == KeyEvent.KEYCODE_BACK 
     && event.getRepeatCount() == 0) { 
    // Take care of calling this method on earlier versions of 
    // the platform where it doesn't exist. 
    onBackPressed(); 
} 

return super.onKeyDown(keyCode, event); 
} 

@Override 
public void onBackPressed() { 
// This will be called either automatically for you on 2.0 
// or later, or by the code above on earlier versions of the 
// platform. 
return; 
} 
+0

謝謝你的幫助 – RMK 2010-07-28 10:29:56

相關問題