Note that there are some explanatory texts on larger screens.

plurals
  1. POTargetApi not taken into account
    text
    copied!<p>In one of our methods, we use smoothScrolling in a list view. As this method is not available before API Level 8 (FROYO), we used the TargetApi annotation to prevent the method from being called in previous SDK versions.</p> <p>As you can see, we <em>do</em> use TargetApi annotation both in class definition and in statements that use the objects of the class. This is more than needed. </p> <p>Our problem is that the TargetApi annotation is not taken into account and make our emulator crash in version ECLAIR (SDK 7). By tracing, we just realize that the code that should only be executed in versions 8+ is also executed in version 7.</p> <p>Are we missing something?</p> <p>This code is in a listener : </p> <pre><code>@TargetApi(8) private final class MyOnMenuExpandListener implements OnMenuExpandListener { @Override public void onMenuExpanded( int position ) { doScrollIfNeeded( position ); } @Override public void onMenuCollapsed( int position ) { doScrollIfNeeded( position ); } protected void doScrollIfNeeded( int position ) { if ( mListViewDocuments.getLastVisiblePosition() - 2 &lt; position ) { mListViewDocuments.smoothScrollToPosition( position + 1 ); } } } </code></pre> <p>And the listener is registered this way :</p> <pre><code>@TargetApi(8) private void allowSmothScrollIfSupported() { if ( Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.FROYO ) { //This if should not be necessary with annotation but it is not taken into account by emulator Log.d( LOG_TAG, "Smooth scroll support installed." ); folderContentAdapter.setOnMenuExpandListener( new MyOnMenuExpandListener() ); } } </code></pre> <p>BTW, we run the code in debug mode, so the issue is not related to obfuscation removing annotations.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload