Declare intent constructor? / Launch an activity?

So I get that you can access Native java/android methods using Declares, and I’ve seen the examples but I’ve only ever seen functions/subs declared (I still don’t know what the difference is).

But I can’t seem to find any example of declaring a constructor specifically, I want to start a new activity/launch another app and it doesn’t seem there’s any built-in method of doing this.

My understanding is though, I should be able to achieve this if I can:

  1. Construct a new intent.
  2. setClassName on the new object, to the package and activity I want to launch.
  3. Call android.app.Activity.StartActivity passing the intent as an parameter.

I attempted some of the following:

Declare Function IntentConstructor Lib "android.content.Intent" Alias "Intent" ()
Declare Sub StartActivity Lib "android.app.Activity" Alias "startActivity" (intent As Ptr)
Declare Sub setClassName Lib "android.content.Intent" Alias "setClassName" (intent as Ptr, packageName as CString, className as CString)

Dim oIntent As Ptr = INtentConstructor()
setClassName(oIntent,"com.packagename","com.packagename.activity")
StartActivity(oIntent)

This doesn’t work but the primary failure seems to be at the constructor itself, wondering if anyone has successfully done this?

EDIT:
I’d like to add, I know it should be similar to other platforms; but after googling and searching I also haven’t seen anyone specifically import a constructor of an object and then call it somehow.

I’m not sure how this would work even if a class was exported from say a windows DLL, I’d assume you’d need to reference the constructor as a Function in the declare but doing Intent.Intent isn’t valid either.

Between functions and subroutines, you mean? A function returns a value, a sub does not.

2 Likes

Thanks for the clarification.