Android Question Splash screen in Android 12

Hello
How can I make my b4a splash screen compatible with Android 12?
As you know, there is a mandatory splash in Android 12 that displays the program icon in a small form and after a few seconds the program starts. This has caused my app to have two splashes on Android 12!
Here is how to implement it in Android Studio, but I don't know how to use it in B4A:
Thankful
 
Solution
You can't do that from B4A as you need to add code to the Main activity creation event which is not exposed in B4A
It is possible. There is an _oncreate hook: https://www.b4x.com/android/forum/threads/inline-java-code.50141/#content

B4X:
#If JAVA
import androidx.core.splashscreen.SplashScreen;
public void _onCreate() {
    BA.Log("onCreate");
      SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
}
#End If

I've attached a project that implements some of the steps. It looks like the simplest solution is to remove the custom splash activity.
You can't do that from B4A as you need to add code to the Main activity creation event which is not exposed in B4A. Unless Erel decides otherwise you are stuck with the default Android 12 splash screen displaying when your app starts.
I believe that whatever we can do in Android Studio or other IDEs, we can also do it in b4a! There is no such thing as impossible in the world of programming!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can't do that from B4A as you need to add code to the Main activity creation event which is not exposed in B4A
It is possible. There is an _oncreate hook: https://www.b4x.com/android/forum/threads/inline-java-code.50141/#content

B4X:
#If JAVA
import androidx.core.splashscreen.SplashScreen;
public void _onCreate() {
    BA.Log("onCreate");
      SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
}
#End If

I've attached a project that implements some of the steps. It looks like the simplest solution is to remove the custom splash activity.
 

Attachments

  • Project.zip
    92 KB · Views: 107
Upvote 0
Solution
It is possible. There is an _oncreate hook: https://www.b4x.com/android/forum/threads/inline-java-code.50141/#content

B4X:
#If JAVA
import androidx.core.splashscreen.SplashScreen;
public void _onCreate() {
    BA.Log("onCreate");
      SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
}
#End If

I've attached a project that implements some of the steps. It looks like the simplest solution is to remove the custom splash activity.
Unfortunately, it gives force close on Android 12. Of course, I also tested it on Android 7, but the same error occurs:
B4X:
--------- beginning of crash
onCreate
java.lang.RuntimeException: Unable to start activity ComponentInfo{b4a.example/b4a.example.main}: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6121)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.BA.runHook(BA.java:185)
    at b4a.example.main.onCreate(main.java:52)
    at android.app.Activity.performCreate(Activity.java:6760)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
    ... 9 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.runHook(BA.java:182)
    ... 13 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
    at androidx.core.splashscreen.SplashScreen$Companion.installSplashScreen(SplashScreen.kt)
    at androidx.core.splashscreen.SplashScreen.installSplashScreen(SplashScreen.kt)
    at b4a.example.main._onCreate(main.java:458)
    ... 15 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.jvm.internal.Intrinsics" on path: DexPathList[[zip file "/data/app/b4a.example-1/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-1/lib/x86_64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
 
Upvote 0
The problem is solved, dear Erel!
I am serious, you are a genius that the world may not see again for decades!
Thank you for making b4a and making a change in the world...
 
Upvote 0
Your source works without problems, but when I copied the codes into an empty project for testing, I encountered the same error as I posted in post #5. I am attaching the source, please see where the problem is!
Also in your source I changed the color to #ffffff in the manifest but the Android 12 mandatory splash background is still blue. Another problem is that the splash screen icon is round, how can I make it rectangular and how can I change its size?

I know your project is based on B4xPages request, but I want to use this to update one of my old projects.
 

Attachments

  • test.zip
    1 KB · Views: 54
Upvote 0

agraham

Expert
Licensed User
Longtime User
I get this error trying to run Erels' example. I've reinstalled B4A v12.00 and a new SDK from commandlinetools-win-9123335_latest.zip and resources_11_22.zip and it still errors. What am I missing?
B4A Version: 12.00
Parsing code. (0.02s)
Java Version: 8
Building folders structure. (0.02s)
Running custom action. (0.05s)
Compiling code. (0.04s)
Compiling layouts code. (0.03s)
Organizing libraries. Error
Maven artifact not found: androidx.core/core-splashscreen
Source: androidx.core:core-splashscreen
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I want to use this to update one of my old projects
Here's a very bare bones non B4XPages version of Erels' example.

@Erel - What is all the IME stuff doing in your B4XPages example?
 

Attachments

  • SplashNonB4XPages.zip
    22.9 KB · Views: 69
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your source works without problems, but when I copied the codes into an empty project for testing, I encountered the same error as I posted in post #5. I am attaching the source, please see where the problem is!
You are missing the AppCompat library which is required for a few dependecies.
 
Upvote 0
Top