|
Getting the correct context to use for AppCompatActivity in an external library |
Iniciado por Thysie, jan., 13 2020 3:05 PM - Sem resposta |
| |
| | | |
|
| |
Membro registado 6 mensagems |
|
Publicado em janeiro, 13 2020 - 3:05 PM |
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 |
| |
| |
| | | |
|
| | | | |
| | |
|