Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by mrpasqal · Jul 24, 2015 at 03:31 PM · androidresumeactivityintent

Restoring Unity3d Android application with another activity on top

I need the following problem to be resolved:

From the UnityPlayerNativeActivity I am starting a standard Android activity (may be mine, may be with an ad from the ad network - nevermind). When the game is being hidden with this activity on top (not the Unity one) by pressing the home button, as a user I have two ways of restoring it:

  • from the Recently used apps screen - the app is being restored to the same state, when it was minimized (that is what I expect to happen);

  • from the launcher, what causes the game's UnityPlayerNativeActivity is being restored with losing all other activities, that have been opened on top of it.

These activities are lost somehow (in a way I don't exactly know, what has happened with them). My game's logic depends on the result of the processes happening there, ie. I need to know, that this particular activity has been exited in any specific way (give a callback for example).

Do you know how I can bring this Unity activity back from launcher with all activities above it, as it was while minimizing it?

I want to understand the difference between the ways of restoring the app from Recently used screen and the launcher. I guess it is related to the intent-filter section within AndroidManifest.xml file, which is included within UnityPlayerNativeActivity entry.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by mrpasqal · Jul 27, 2015 at 03:56 PM

The solution turned out to be quite simple, but not so obvious.

It has turned out, that the AndroidManifest.xml configuration that is being produced by Unity by default is causing this problem. For the main activity that is being started from launcher the following parameters are defined (taken from decompiled app):

     <activity 
         android:alwaysRetainTaskState="true"
         android:clearTaskOnLaunch="true"
         android:configChanges="locale|fontScale|keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode" 
         android:label="@string/app_name" 
         android:launchMode="singleTask" 
         android:name="com.unity3d.player.UnityPlayerNativeActivity" 
         android:screenOrientation="fullSensor" 
         launchMode="singleTask">

         <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true"/>

         <intent-filter>
             <action android:name="android.intent.action.MAIN"/>
             <category android:name="android.intent.category.LAUNCHER"/>
             <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
         </intent-filter>
     </activity>

The problematic behaviour is being caused by these 2 parameters:

     android:clearTaskOnLaunch="true"
     android:launchMode="singleTask"

When the I change them to:

     android:clearTaskOnLaunch="false"
     android:launchMode="standard"

Then the app is resuming fine from the launcher.

The correct parameters should be set as follows:

     <activity 
         android:alwaysRetainTaskState="true" 
         android:clearTaskOnLaunch="false"
         android:configChanges="locale|fontScale|keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode" 
         android:label="@string/app_name" 
         android:launchMode="standard" 
         android:name="com.unity3d.player.UnityPlayerNativeActivity" 
         android:screenOrientation="fullSensor" 
         launchMode="standard">

         <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true"/>

         <intent-filter>
             <action android:name="android.intent.action.MAIN"/>
             <category android:name="android.intent.category.LAUNCHER"/>
             <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
         </intent-filter>
     </activity>

Note: While I am able to set the value android:clearTaskOnLaunch="false" for this activity explicitly, the launchMode parameter will be forced by Unity3d and set to "singleTask". I managed to change and check it by decompiling the app and rebuilding from these changed resources. I wonder if there is any elegant way to set this value.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image d4Rk · Dec 21, 2015 at 09:11 AM 0
Share

Did you try modifying the $$anonymous$$anifest in a PostProcess build step?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Pass an image from Android activity to unity 0 Answers

Unity / QCAR Activity on Android 1 Answer

Android plugin & Activity help needed - "GetMethodID method not found" problems 0 Answers

sound paused in android multiple Activities 0 Answers

Read intent from Android Studio in Unity 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges