As the title says, CastContext.getSharedInstance(Context) is now deprecated:
getSharedInstance(Context context): This method is deprecated. Use getSharedInstance(Context, Executor) instead to handle the exception when Cast SDK fails to load the internal Cast module. https://developers.google.com/android/reference/com/google/android/gms/cast/framework/CastContext
What would be the correct way to specify an Executor and return the CastContext? I got it working like this but I wonder if this is the best way to do it:
CastContext
.getSharedInstance(context, Executors.newSingleThreadExecutor())
.addOnSuccessListener(castContext -> {
//do something with castContext
})
.addOnFailureListener(exception -> {
//throw exception
});
Your approach is good for retrieving CastContext asynchronously.
But, in the official cast sample app, they are retrieving CastContext synchronously by directly calling getResult() on the getSharedInstance() task.
val castExecutor = Executors.newSingleThreadExecutor()
val castContext = CastContext.getSharedInstance(this, castExecutor).result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With