Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CastContext.getSharedInstance(Context) is now deprecated

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
    });
like image 994
nh7 Avatar asked May 02 '26 18:05

nh7


1 Answers

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
like image 115
Praveen Avatar answered May 05 '26 08:05

Praveen