diff --git a/platform/android/java/app/AndroidManifest.xml b/platform/android/java/app/AndroidManifest.xml index 1e4fce2eb..822321be4 100644 --- a/platform/android/java/app/AndroidManifest.xml +++ b/platform/android/java/app/AndroidManifest.xml @@ -41,7 +41,7 @@ android:name=".PandemoniumApp" android:label="@string/pandemonium_project_name_string" android:theme="@style/PandemoniumAppSplashTheme" - android:launchMode="singleTask" + android:launchMode="singleInstance" android:excludeFromRecents="false" android:exported="true" android:screenOrientation="landscape" diff --git a/platform/android/java/editor/src/main/java/net/relintai/pandemonium/editor/PandemoniumEditor.kt b/platform/android/java/editor/src/main/java/net/relintai/pandemonium/editor/PandemoniumEditor.kt index 68fd59491..a24373bbf 100644 --- a/platform/android/java/editor/src/main/java/net/relintai/pandemonium/editor/PandemoniumEditor.kt +++ b/platform/android/java/editor/src/main/java/net/relintai/pandemonium/editor/PandemoniumEditor.kt @@ -63,7 +63,7 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() { private val TAG = PandemoniumEditor::class.java.simpleName private const val WAIT_FOR_DEBUGGER = false - private const val EXTRA_FORCE_QUIT = "force_quit_requested" + private const val EXTRA_COMMAND_LINE_PARAMS = "command_line_params" private const val EDITOR_ID = 777 @@ -97,7 +97,9 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() { // requested on demand based on use-cases. PermissionsUtil.requestManifestPermissions(this, setOf(Manifest.permission.RECORD_AUDIO)) - handleIntentParams(intent) + val params = intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS) + Log.d(TAG, "Received parameters ${params.contentToString()}") + updateCommandLineParams(params) if (BuildConfig.BUILD_TYPE == "dev" && WAIT_FOR_DEBUGGER) { Debug.waitForDebugger(); @@ -106,25 +108,6 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() { super.onCreate(savedInstanceState); } - override fun onNewIntent(newIntent: Intent) { - intent = newIntent - handleIntentParams(newIntent) - super.onNewIntent(newIntent) - } - - private fun handleIntentParams(receivedIntent: Intent) { - val forceQuitRequested = receivedIntent.getBooleanExtra(EXTRA_FORCE_QUIT, false) - if (forceQuitRequested) { - Log.d(TAG, "Force quit requested, terminating..") - ProcessPhoenix.forceQuit(this) - return - } - - val params = receivedIntent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS) - Log.d(TAG, "Received parameters ${params.contentToString()}") - updateCommandLineParams(params) - } - override fun onPandemoniumSetupCompleted() { super.onPandemoniumSetupCompleted() val longPressEnabled = enableLongPressGestures() @@ -155,7 +138,7 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() { private fun updateCommandLineParams(args: Array?) { // Update the list of command line params with the new args commandLineParams.clear() - if (args != null && args.isNotEmpty()) { + if (!args.isNullOrEmpty()) { commandLineParams.addAll(listOf(*args)) } if (BuildConfig.BUILD_TYPE == "dev") { @@ -202,6 +185,7 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() { ProcessPhoenix.triggerRebirth(this, newInstance) } else { Log.d(TAG, "Starting $targetClass with parameters ${args.contentToString()}") + newInstance.putExtra(EXTRA_NEW_LAUNCH, true) startActivity(newInstance) } diff --git a/platform/android/java/lib/src/net/relintai/pandemonium/pandemonium/FullScreenPandemoniumApp.java b/platform/android/java/lib/src/net/relintai/pandemonium/pandemonium/FullScreenPandemoniumApp.java index 521157a29..84a0a6851 100644 --- a/platform/android/java/lib/src/net/relintai/pandemonium/pandemonium/FullScreenPandemoniumApp.java +++ b/platform/android/java/lib/src/net/relintai/pandemonium/pandemonium/FullScreenPandemoniumApp.java @@ -50,6 +50,9 @@ import androidx.fragment.app.FragmentActivity; public abstract class FullScreenPandemoniumApp extends FragmentActivity implements PandemoniumHost { private static final String TAG = FullScreenPandemoniumApp.class.getSimpleName(); + protected static final String EXTRA_FORCE_QUIT = "force_quit_requested"; + protected static final String EXTRA_NEW_LAUNCH = "new_launch_requested"; + @Nullable private Pandemonium pandemoniumFragment; @@ -58,6 +61,8 @@ public abstract class FullScreenPandemoniumApp extends FragmentActivity implemen super.onCreate(savedInstanceState); setContentView(R.layout.pandemonium_app_layout); + handleStartIntent(getIntent(), true); + Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.pandemonium_fragment_container); if (currentFragment instanceof Pandemonium) { @@ -109,11 +114,36 @@ public abstract class FullScreenPandemoniumApp extends FragmentActivity implemen @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); + + setIntent(intent); + + handleStartIntent(intent, false); + if (pandemoniumFragment != null) { pandemoniumFragment.onNewIntent(intent); } } + private void handleStartIntent(Intent intent, boolean newLaunch) { + boolean forceQuitRequested = intent.getBooleanExtra(EXTRA_FORCE_QUIT, false); + if (forceQuitRequested) { + Log.d(TAG, "Force quit requested, terminating.."); + ProcessPhoenix.forceQuit(this); + return; + } + + if (!newLaunch) { + boolean newLaunchRequested = intent.getBooleanExtra(EXTRA_NEW_LAUNCH, false); + if (newLaunchRequested) { + Log.d(TAG, "New launch requested, restarting.."); + + Intent restartIntent = new Intent(intent).putExtra(EXTRA_NEW_LAUNCH, false); + ProcessPhoenix.triggerRebirth(this, restartIntent); + return; + } + } + } + @CallSuper @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {