forked from androidannotations/androidannotations
-
Notifications
You must be signed in to change notification settings - Fork 0
Android Backward Compatibility
pyricau edited this page Jan 14, 2012
·
4 revisions
Since AndroidAnnotations 1.0
Since Android 2.0, activities can implement onBackPressed() to modify the default behavior when the user presses the back key.
There was an article on the Android blog that showed how to reproduce this for pre 2.0 Android versions.
We automatically support that since AndroidAnnotations 2.1 (with issue 46): if an @EActivity annotated class has an onBackPressed() method, the generated class adds the needed code for support on pre 2.0 Android versions.
For instance:
@EActivity
public class MyActivity extends Activity {
public void onBackPressed() {
// Do something
}
}Generates:
public final class MyActivity_ extends MyActivity
{
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (((SdkVersionHelper.getSdkInt()< 5)&&(keyCode == KeyEvent.KEYCODE_BACK))&&(event.getRepeatCount() == 0)) {
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
}AndroidAnnotations was created by Pierre-Yves Ricau and is sponsored by eBusinessInformations.
04/11/2012 The 2.7 release is out
- Get started!
- Download
- Cookbook, full of recipes
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow