I have a MainActivity that has a long cold start on some devices so I would like to use splash screen and trigger it from a function on my MainActivity to finish.
I use my SplashActivity as the launcher and then load my MainActivity. This works when I set it in SplashActivity, but my SplashActivity ends abruptly and still getting the blank screen on cold start then starting the app main loop.
Below code ends the splash screen soon and runs the MainActivity still with a long cold start blank screen.
I know this will also work with a timeout/timer as I have seen on most answers, but I would like to trigger it inside my MainActivity by using function or once my NativeActivity main loop starts. I am using JNI to call java functions from C++.
Edit: I have also found an alternative solution on using fragments inside MainActivity, but have no idea where to start as the author did not share the solution in detail here:
https://stackoverflow.com/a/44444946/11736918
public class SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
My MainActivity just loads another Native .so library.
public class MainActivity extends NativeActivity {
static {
System.loadLibrary("MyLib");
}
public void RemoveSplash() {
// Ideally I will use this to trigger it from my C++ code using JNI.
}
}
Here is my AndroidManifest.xml
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="native-activity" />
</activity>
<activity android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>