The Frame Rate API allows applications to communicate their desired frame rate to the Android platform to enhance the user experience. The API is useful since many devices now offer varying refresh rates like 60Hz, 90Hz, or 120Hz.
Standard applications don’t require a display refresh rate above 60Hz, hence it is advisable to avoid higher frequencies to avoid unnecessary energy consumption.
The rule flags an issue when setFrameRate() is invoked with a frameRate higher than 60Hz for android.view.Surface and
android.view.SurfaceControl.Transaction.
It’s important to note that the scheduler considers several factors when determining the display refresh rate. Therefore, using
setFrameRate() doesn’t guarantee your app will achieve the requested frame rate.
Use a frame rate of maximum 60Hz, unless you have a strong reason to used higher rates. Valid exceptions are gaming apps, especially those with fast-paced action or high-quality graphics, or AR/VR apps.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SurfaceView surfaceView = findViewById(R.id.my_surface_view);
Surface surface = surfaceView.getHolder().getSurface();
surface.setFrameRate(90.0f, Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE); // Noncompliant
}
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SurfaceView surfaceView = findViewById(R.id.my_surface_view);
Surface surface = surfaceView.getHolder().getSurface();
surface.setFrameRate(60.0f, Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE); // Compliant
}
}