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.
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.
You may find this blog post useful:
http://inthecheesefactory.com/blog/understand-android-activity-launchmode/en
Related
I have an Android application with a default activity which is defined in the AndroidManifest.xml:
<application
android:label="NameOfMyApp"
...
<activity
android:name=".LoginActivity"
android:label="Login">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.rei0d.wop.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
It seems that android:label="NameOfMyApp" will be overwritten if there is an attribut android:label for the default activity.
So I want to change the application's name to something else than Login, NameOfMyApp for example, without changing the android:label of the Login activity. Is this possible? Or do I have to create a blanc activity as default activity which starts the Login activity?
Well, there are multiple possibilities to fix this issue, unfortunately some of them don’t work on all devices.
It seems like that the Launcher takes the application-name from the label of the "Entry Activity". You can prevent his by adding the following attribute to your intent-filer:
<intent-filter android:label="NameOfMyApp">
Unfortunately some Launchers may ignore this, so I wouldn’t go for this solution.
I would recommend you to change the title of your Login-Activity programatically. So first of all change the android:label value of your .LoginActivity to the name of your app.
In onCreate or somewhere else set the title (assuming that you’re using the ActionBar).
getActionBar().setTitle("Login");
Note: You should get the title from a strings-xml file of course
I'm having a problem with my app after changing the default activity in the manifest. This is the manifest after i changed it. As far as i can see it's syntactically correct.
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".loginActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="CouncilPlannerActivity"></activity>
<activity android:name="MainTabActivity"></activity>
<activity android:name="MapTabActivity" android:theme="#android:style/Theme.NoTitleBar"></activity>
<activity android:name="NodeFormActivity"></activity>
<activity android:name="viewNewsActivity"></activity>
</application>
The problem is when i deploy the app to my device it works fine first time. However, when i close the app with the home button it refuses to open again. Clicking the icon in the devices app list doesn't do anything.
If i change the default activity to the one it was at originally it works fine. Is this a bug or is there another reference to a default activity that i'm missing?
I'm developing on Android 2.2 if that makes a difference.
I just noticed the logcat spits out an error when i try to open the app : "Permission Denied: checkComponentPermission() reqUID10064"
You probably need to post the loginActivity in question here so we can see if there are any problems in the activity. Otherwise double check that the loginActivity is in the same package as the other activities, if its not you need to change the ".loginActivity" part of the manifest to its relative location to the main package, aka "somename.loginActivity"
I think the problem is in loginActivity class. May be you check for already loggined user and finish activity in this case?
my android application crashes and shows force close when i tilt the mobile phone. is there any suggestions that i can remove such problem? By the way i am developing a LBS application which uses the google maps (MapView).
I have a splash screen and then shown a ListActivity as below :
<activity android:name=".Splash" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Home" android:label="#string/app_name" android:configChanges="orientation" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="com.nepways.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
what is wrong with my declaration, the splash screen loads and list activity is also whown correctly but when i change the orientation the application is closed. Please help me.
When you change your orientation the activity is restarted
look at the logcat to see what exception causes your application to FC
You can change your manifest to disable activity restarting by customizing configChanges, if you stil have the problem override onConfigurationChanged() to fix what is generating this exception (like initialize something that may cause a nullpointer)
First of all as it is said the app is restarting (or as it is said in reference redrawing) each time when you change orientation.
To block it in your manifest file in activity you have to put this line which describes the activity orientation:
<activity android:name=".Splash"
android:label="#string/app_name"
android:screenOrientation="portrait">...
And about this buttons, or keymaps. Telling the truth Ive got thise warnings sometimes but it doesnt change anything in my app. So first change the orientation settings and then it should work correct.
If you want use other screen orientation remember to check here:
http://developer.android.com/guide/topics/manifest/activity-element.html
If you want to avoid restarting your activity on orientation change, you can put this in the activity in the manifest file:
android:configChanges="orientation"
Otherwise, we will need to see more code, and a stacktrace.
I am developing app, which works as kind of launching hub for other applications. Thing is, my application is always destroyed by system after about 75 seconds after any other external activity is launched from it and stays active.
For instance I am launching browser, or any activity with chooser in it. Then waiting for 75 seconds and back button will take me to Home. With chooser activity I even may see my application exits in background.
How do I avoid this, what may be the reason? My guess is I should have some sort of affinity with launched activities, but I may be wrong.
Here is how I describe my activities. The app is called Speaktoit Assistant on the market you can test it.
<activity
android:name="com.speaktoit.assistant.main.MainActivity"
android:theme="#style/Theme.DoNotDim"
android:windowSoftInputMode="stateHidden|adjustPan"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTop">
</activity>
<activity
android:name="com.speaktoit.assistant.SplashActivity"
android:label="Assistant"
android:theme="#android:style/Theme.Light.NoTitleBar"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation"
android:finishOnTaskLaunch="true"
android:noHistory="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
UPDATE:
Ok, Looks like system halts my app and returns it to initial launcher activity and since SplashActivity is finishOnTaskLaunch="true", then it just exists. Question is how make android to return to MainActivity instead ...
UPDATE 2:
Ok, I have found killTask buried in the code. Problem solved :).
Did you try removing singletop launchmode?
If I use this code in my Manifest file:
<activity android:name=".MyAct"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"> //<-SEE THIS
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
As you can see I am declaring that the activity shall not be restarted when the screen rotation and keyboard visibility have been changed.
However, does this mean that the method onConfigurationChanged() will be called ONLY in case of these two events (in other cases the activity shall restart)?
Or it means that the activity does not restart even if only one attribute has been used?
I haven't been able to find this answer in the documentation.
Correct. It means that the activity does not restart even if only one attribute has been used. The onConfigurationChanged() method will be envoked if one of the attribute occur, i.e for those which are not specified, the activity will restart when they occur.