WinDev Mobile (Android) - Passing the correct context for AppCompatActivity

TheOneAtFault

New Member
Joined
Jan 14, 2020
Messages
2
Ahoy hoay!

Bare with me on this one.

So some background; I am working in a development environment called WinDev, the mobile edition and it uses a language called WLanguage. It's handy for cross platform development, think Xamarin, and they make use of a customized android/gradle(not sure what the correct terminology is to use) and allow you to write Java procedures for some custom development.

What I am trying to achieve:
I have an external .aar library that I want to make use of. Now the library makes use of the AppCompatActivity class and on of the methods required an instance of this to be passed as a parameter:

Code:
public Example(AppCompatActivity var1, boolean var2, ServiceConfigurationEnum var3) {
}
The trick is, The Android version used by WinDev does not seem to have support for the "android.support.v7.app.AppCompatActivity;" library.

So I need to pass an instance of context from WinDev but the only two methods I can use to get some form of context are "getApplicationContext()" and "getCurrentActivity()"

From what I understand I should be able to use "getCurrentActivity()" and pass that to my .aar library where I then cast the "Activity" to "AppCompatActivity".

From WinDev:
Code:
imports ...
public static String Beta(){
    //Context context = getApplicationContext();
    Activity activity = getCurrentActivity();
   
    Oscar oscar = new Oscar(activity);  
    String response = oscar.run();
    return response;
}
In my .aar:
Code:
public Oscar(Activity activity) {
    AppCompatActivity altContext = (AppCompatActivity) activity; //error occurs here
    blob = new Example(altContext, true, ServiceConfigurationEnum.UAT);
}
But this results in an exception stating the following:
"Failed resolution of: Landroidx/appcompat/app/AppCompatActivity; "

Now I am quite stuck and can't find my a way around this. If someone can advise me on this or point out my mistake, it would be greatly appreciated.

Thanks a bunch!
 
Last edited:

Sysem

Expert Member
Joined
Mar 26, 2009
Messages
1,891
Unfortunately, if WinDev doesn't support `AppCompatActivity`, you're not going to be able to do what you want. Do you really need an Activity and not just the context associated with it?
 

TheOneAtFault

New Member
Joined
Jan 14, 2020
Messages
2
Looking at the 3rd party(think I forgot to mention this) library, it makes use of both. If I understand correctly.

Code:
private final AppCompatActivity _activity;
private final Context _context;

public Factory(AppCompatActivity var1, boolean var2, ServiceConfigurationEnum var3) {
        this._activity = var1;
        this._context = var1.getBaseContext();
...       
}
But if it is not possible to get around the lack of support for the "AppCompatActivity" library, then I'll look at other alternatives.
 

Sysem

Expert Member
Joined
Mar 26, 2009
Messages
1,891
Never heard of WinDev, but I assume they're not supporting newer Android versions (or haven't included support v7 as a dependency). In fact, the support libs have been deprecated in favor of androidx libs, so other libraries might conflict if they've updated but WinDev hasn't
 
Top