- Home /
Unity is Embedded into Android App. Only Unity Activity gets killed upon pressing App Icon
I integrated Unity into my Android app. The problem I am facing is when I put the app into the background while Unity Activity is focused and then I open the app via app icon (no recently opened apps list), the unity activity gets destroyed and it brings MainActivity back to be focused. I dont know if it is important but I use react-native.
This is my manifest file:
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="false"
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<activity
android:process=":Unity"
android:launchMode="singleTask"
android:hardwareAccelerated="true"
android:screenOrientation="portrait"
android:name=".MainUnityActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"/>
</application>
What I have tried:
changing launch modes. They dont work.... If I make launch mode standard, react-native will always restart js bundle. Unity Activity should also be singleTask as RN. I used the code at MainActivity in onCreate() method
if(!taskRoot()) finish();
I am not doing anything supernatural. I just launch new Intent and that is it. My expected behavior for it is to resume Unity activity when opening an app via app icon if the app was in the background. If you need more information, don't hesitate to ask. Please, help.
Your answer
Follow this Question
Related Questions
Embedding unity into existing android app: UnityPlayer.quit kills app process 0 Answers
How to use multiple unity module or unityLibrary into native android application 0 Answers
Crash reporting of Embedded Unity game (Android),Crash report for embedded Unity game (Android) 0 Answers
android Bluetooth multiplayer 1 Answer