SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Android Java code modernization (lots of deprecation warnings)

Open leonstyhre opened this issue 1 year ago • 0 comments

Hi!

There are a lot of deprecation warnings for the Java code when building for Android, a bit more than 60. Here are some examples:

HIDDeviceManager.java:69: warning: [deprecation] <T>getParcelableExtra(String) in Intent has been deprecated
HIDDeviceBLESteamController.java:96: warning: [deprecation] setValue(byte[]) in BluetoothGattCharacteristic has been deprecated
SDLSurface.java:54: warning: [deprecation] getDefaultDisplay() in WindowManager has been deprecated
SDLControllerManager.java:561: warning: [deprecation] VIBRATOR_SERVICE in Context has been deprecated
SDLActivity.java:578: warning: [deprecation] locale in Configuration has been deprecated
SDLActivity.java:1582: warning: [deprecation] setColorFilter(int,Mode) in Drawable has been deprecated

In addition to this the SDLActivity class extends Activity which is problematic as it forces you to for instance use the startActivityForResult() and onActivityResult() methods which Google strongly recommends to not use any longer. Instead they recommend using the new AndroidX Activity Result API which requires that you extend that class, or alternatively AppCompatActivity.

I don't have much knowledge about this topic so can't explain it better and I'm not sure what the implications for SDL would be, but it seems like moving to the newer classes and APIs is required as Google will likely deprecate the old methods at some point.

For more info about the specific methods I mentioned this page has some details: https://developer.android.com/training/basics/intents/result

The way I have implemented the newer Activity Result API in ES-DE is via a Kotlin class as I need that anyway for Jetpack Compose, but there is one instance where I have to launch an activity from the Java code and then I have to use the old method.

leonstyhre avatar Jan 20 '24 11:01 leonstyhre