ورود

View Full Version : فرق این دو کد در چیست؟



sco1385
چهارشنبه 24 اردیبهشت 1393, 12:32 عصر
استادان گرامی

فرق این دو کد در چیست؟

اگر هر دو یک کار را انجام می‌دهند، کدام یک بهتر است؟



@Override
public void onBackPressed() {
if(myWebView.canGoBack()) {
myWebView.goBack();
} else {
// Let the system handle the back button
super.onBackPressed();
}
}





@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {


// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}


ممنونم

Nevercom
چهارشنبه 24 اردیبهشت 1393, 13:21 عصر
فرقش در این هست که متد onBackPressed فقط فشرده شدن کلید Back رو مدیریت می کنه و از API 8 به بالا در دسترس هست