Reputation: 91
My project minSdkVersion is set to 10.
MainActivity is a ActionBarActivity from support.v7.app.AppCompatActivity.
the default method .invalidateOptionsMenu()
crashes on Android 2.3.7 (api10) so I must use the compatibility method .supportInvalidateOptionsMenu()
;
and I have a question:
Why does Android Studio not alert me that invalidateOptionsMenu
is not for the older api?
I understood this only after I succesfully build an apk and ran it on an api10 device and it crashed...
How can I check without any real testing?
Same thing with the PopupMenu
if I mistakenly import android.widget.PopupMenu
instead of android.support.v7.widget.PopupMenu
I do not get a warning from AndroidStudio that minSdk set to 10 and PopupMenu will not work on old Android
Upvotes: 2
Views: 188
Reputation: 409
The Google documentation for supporting different platform versions provides some good insight. They even address the issue you were dealing with:
private void setUpActionBar() {
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
My best suggestion beyond that would be to set your target API to the platform you want to test, see if it gives you any compiler level flags, and if not give it a quick run in the emulator. Hope that helps!
Upvotes: 2