Java Question Creating a simple library error

apty

Active Member
Licensed User
Longtime User
I am trying to create a simple library for launching an intent.
The below java code gives me an error in b4a after compiling (that context is required). Please assist

B4X:
import android.content.Context;
import android.content.Intent;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;

//Library version


//Applicable only to this class
@ShortName("NextLauncherThreed")



public class NextLauncher {
    public static void NextLauncherlaunch(Context context) {
   
        Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage("com.gtp.nextlauncher");
        if (launchIntentForPackage == null) {
            launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage("com.gtp.nextlauncher.trial");
        }
        Intent intent = new Intent("com.gau.go.launcherex.MyThemes.mythemeaction");
        intent.putExtra("type", 1);
        intent.putExtra("pkgname", context.getPackageName());
        context.sendBroadcast(intent);
        context.startActivity(launchIntentForPackage);
       
    }
   
}
 

warwound

Expert
Licensed User
Longtime User
You can add a BA type parameter to any method that is called from b4a.
The parameter will not be exposed or seen within the b4a IDE - it's a hidden parameter in the IDE:

B4X:
import android.content.Context;
import android.content.Intent;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;

//Library version


//Applicable only to this class
@ShortName("NextLauncherThreed")



public class NextLauncher {
    public static void NextLauncherlaunch(BA ba) {
   
        Intent launchIntentForPackage = ba.context.getPackageManager().getLaunchIntentForPackage("com.gtp.nextlauncher");
        if (launchIntentForPackage == null) {
            launchIntentForPackage = ba.context.getPackageManager().getLaunchIntentForPackage("com.gtp.nextlauncher.trial");
        }
        Intent intent = new Intent("com.gau.go.launcherex.MyThemes.mythemeaction");
        intent.putExtra("type", 1);
        intent.putExtra("pkgname", ba.context.getPackageName());
        ba.context.sendBroadcast(intent);
        ba.context.startActivity(launchIntentForPackage);
       
    }
   
}

The instance of BA has a property named 'context' and that's what you are looking for.
 
Top