Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Press power button to lock the phone, then the running apk quit.

Discussion in 'Android' started by ZorroBlade, Mar 18, 2012.

  1. ZorroBlade

    ZorroBlade

    Joined:
    Jul 7, 2011
    Posts:
    25
    I have found that when we release a apk using unity3D purely, and there's no Plugins/Android , the apk works well when the user lock the phone and resume .The game resumed as we expected.
    But when I export the project to eclipse and build the apk as the official document :
    http://unity3d.com/support/documentation/Manual/Android-Integrating Unity With Eclipse.html
    Now the bug happens when the user press power button and lock the phone while playing , the running apk quit. And if the user unlock the phone, the apk start all over again.
    And I notice if I write a plugin and place it under Plugins/Android , the bug happens too.
    So I guess is there any bug in the UnityPlayerActivity or someother things.
    I don't know if anyone have had my problem, sorry for my English. Thanks for any help. :-|
     
  2. ZorroBlade

    ZorroBlade

    Joined:
    Jul 7, 2011
    Posts:
    25
    hi ,guys , i have tried test the whole process a again and again. I think i can locate the bug now. A just clean and empty project ,If we build a "portrait" apk, and integrate it in eclipse, that apk work well on the lock button problem.
    But if you build a "landscape" apk , and modify the AndroidManifest.xml to the start Activity "android:screenOrientation="landscape",
    that bug happen!

    the only log is "Unity onDetachedFromWindow" , when the power button is pressed, then the whole app quit
     
  3. ZorroBlade

    ZorroBlade

    Joined:
    Jul 7, 2011
    Posts:
    25
    I have solved the problem now, what should do is to modify the AndroidManifext.xml ,and add the line :
    android:configChanges="keyboard|keyboardHidden|orientation"
    in Activity.
    Thanks for help.Hope this would help someone else.
     
  4. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    You should always use the most recent AndroidManifest.xml available in the Unity folder. On Windows it can be found in C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\androidplayer

    The current version as of Unity3D 3.5
    PHP:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest
        xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.unity3d.player"
        android:installLocation="preferExternal"
        android:versionCode="1"
        android:versionName="1.0">
        <supports-screens
            android:smallScreens="true"
            android:normalScreens="true"
            android:largeScreens="true"
            android:xlargeScreens="true"
            android:anyDensity="true"/>

        <application
            android:icon="@drawable/app_icon"
            android:label="@string/app_name"
            android:debuggable="true">
            <activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
                      android:label="@string/app_name"
                      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name="com.unity3d.player.UnityPlayerActivity"
                      android:label="@string/app_name"
                      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            </activity>
            <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
                      android:label="@string/app_name"
                      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
                <meta-data android:name="android.app.lib_name" android:value="unity" />
                <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
            </activity>
            <activity android:name="com.unity3d.player.VideoPlayer"
                      android:label="@string/app_name"
                      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            </activity>
        </application>
    </manifest>
    As you see, the configChanges have a lot more parameters, than yours above.

    PHP:
    fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen
    Some of this are new and for Tablets and/or the new Android 4.0 devices (i.e. screenSize and smallestScreenSize being new added with API Level 13

    http://developer.android.com/guide/topics/manifest/activity-element.html#config
     
  5. HazeTI

    HazeTI

    Joined:
    Jan 12, 2012
    Posts:
    83
    Ah great, this helped solve my problem too. Thanks Tseng. Although I had trouble finding this thread in a search because I was using the term sleep and power, rather than lock. So hopefully my using it now might help other searches in the future!
     
  6. rbisso

    rbisso

    Joined:
    Jul 13, 2011
    Posts:
    29
    Thank you so much, ZoMask and Tseng! Was running into similar problems with sliding an Xperia Play open and shut...