PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → Getting the correct context to use for AppCompatActivity in an external library
Getting the correct context to use for AppCompatActivity in an external library
Débuté par Thysie, 13 jan. 2020 15:05 - Aucune réponse
Membre enregistré
6 messages
Posté le 13 janvier 2020 - 15:05
Hello

I am using an external library that takes AppCompatActivity (derived from androidx.appcompat.app.AppCompatActivity) as a parameter.

Neither getApplicationContext or getCurrentActivity seems to be able to provide me the correct context.

When trying to cast the context that gets passed to my library (on both above) to AppCompactActivity within the library, I get an exception stating "Failed resolution of: Landroidx/appcompat/app/AppCompactActivity;"

Java procedure in Windev:
imports ...
public static String init(){
//Context context = getApplicationContext();
Activity activity = getCurrentActivity();

Main main = new Main(activity);
String response = main.run();
return response;
}


and in the library:
public Main(Activity activity) {
        if (activity != null){
            AppCompatActivity altContext = (AppCompatActivity) activity; //error thrown here
            factory = new TransactionFactory(activity, true, ServiceConfigurationEnum.UAT);
        }
else{
return;
}
       
    }


Any suggestions on working around this or getting the context in the correct format to be passed/cast to be usable?

Kind Regards
MJ

P.S.
If someone could tell me why Windev lacks support for androidx libraries that would be great, i.e "import androidx.appcompat.app.AppCompatActivity;"

--
Regards,
Thysie