Hello
My application works like this.
StartUpActivity is called first, which does a lot of the init stuff
Then it launches TvbTabActivity (TabActivity) that has other Activities as its tabs (e.g. BrowseActivity).
The problem that I am seeing is this - when a task-killer app is used to terminate my app on TvbTabActivity/Browse tab, and the app is relaunched again, the system forgoes the normal flow (StartUpActivity is not spawned), but instead restores the last visible activity directly (TvbTabActivity).
How can i force Android to ALWAYS run StartUpActivity first, so that it initializes the app?
Obviously, I dont have this problem when my app crashes on its own, lol, due to an exception, and is then relaunched again.
<application android:icon="#drawable/appicon"
android:label="#string/app_name" android:name="com.xyz.QPApplication"
android:debuggable="true">
<activity android:name=".activity.StartUpActivity" android:configChanges="locale|orientation"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".catalogue.BrowseActivity" android:configChanges="locale|orientation"
android:label="#string/app_name" android:screenOrientation="portrait"
android:launchMode="singleTop">
<intent-filter>
<action android:name="com.xyz.android.intent.action.BROWSE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".activity.TvbTabActivity" android:configChanges="locale|orientation"
android:screenOrientation="portrait" android:launchMode="singleTask">
</activity>
You can't. Android will try to restore the app where it left off. The correct way to handle this is to ensure that you understand the Activity life-cycle and put the appropriate initialization in the appropriate place.
There are a couple of ways to solve your issue, the best would be to check the Android Life-cycle diagram http://code.google.com/android/images/activity_lifecycle.png and try to figure out a way to make the app work within that context.
Of course if you really want to you can kill your own app by calling Activity.finish() when it hits the onPause() or onStop() states, but that is quite an ugly solution.
You can't do anything about this -- what is happening to you is what the force stop API does and is intended to do.
Task killers are abusing that API.
They can no longer use it in 2.2 and later.
If you really want to avoid it, you could limit your app to only 2.2 or later. Or if the problem is users are complaining about them, tell them to stop using task killers. Or if the problem is just that you don't like this happening when you use a task killer, then don't use a task killer.
Also this is the same behavior that happens when the user presses "Force stop" in the manage application's UI. That is generally fine though since the user must explicitly do that, instead of what these task killer apps have been increasingly doing where they just whack stuff in the background without the user being directly involved.
Related
i am using one app, for example chrome with some confidential information and i am switching it to background & i am trying to kill the app.
i uploaded the example image when trying to kill the app. even the session the expired it won't close the information in the killing stage when app comes foreground then only it closes the information. i want the info should be closed or hided when it goes background (In killing stage).
i searched in google i am not getting anything related to this and i don't know whether my search phrase is correct. can anyone pleas help me.
I think ur asking this:
Just add this in manifest file:
android:excludeFromRecents="true"
Example:
<activity
android:name=".MainActivity"
android:excludeFromRecents="true"
android:taskAffinity=".OnInviteActivity"
android:noHistory="true"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
then your app will not show in background or recent app or in menu like that
UPDATE:
for ur app name only u need to add this in Main Activity:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
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
When i download my app from store.
its installed on main screen, and on apps menu ( when i click the circle with 6 dots on it )
when i click from main screen it opens an app, and when i click from the other place..it opens a second app as well.
i need one app running only..
how can this be fixed?
my manifest
<application
android:name="dfsfsdp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".StartupActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I think you aren't running multiples instances (if you are running multiple instances if fail of the mobile), or you see two applications open in the menu what you use to close the running apps (the recent applications menu)?
If you only see one maybe your are restarting the same instance. Look at your StartupActivity or post here to try help you.
If this don't help you, take a look at to read about the lifecycle of an Activity:
http://developer.android.com/training/basics/activity-lifecycle/index.html
Best regards.
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?
I made myself an app: a music player with automatic bookmarking :)
Problem:
If I go "back" to the home page and then try to run the app again, it creates a new instance whereas I want to continue. I might leave music running while I do other things and then I can't pause it or save it because I can't access it!
Failed Solutions:
I've tried singleTop, singleTask, singleInstance and they all don't work!
I can view running apps (Settings > Applications > Manage Applications > Running) but it only let's you "Force stop" them. How about "Bring to front"?! Also, when I finish() my app, I notice it's still "running"!
This site is very awesome and useful and this is my first question :) I looked for answers but couldn't find any that worked :(
Here's the manifest:
<application android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name="Fire"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Back by default closes the activity. You can override this behaviour by catching BACK key, but in your case, you really need Service not activity to play music and control it. Activity is ment to be destroyed when you leave it on BACK really....
Read more here: http://developer.android.com/guide/topics/fundamentals/services.html