How can I resume a running activity? - android

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

Related

Can we destroy instance of an app in the background after opening it from a deep link?

Can we destroy instance of an app in the background after opening it from a deep link? Like you need to login first in that app in your phone before you can proceed in the browser. After successful login, is it possible to destroy the activity which is now in the background (in this case the screen is now the browser)?
I was able to finish the activity and in that case it navigates me back to the browser. But when I try to open the RECENT APPS BUTTON it still shows me the application on background.
Thank you for your help.
In AndroidManifest.xml, add android:excludeFromRecents="true" to MainActivity of your app like below:
<activity android:name=".MainActivity"
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It should work. For details please check here.
Note: If above doesn't work then please try by adding android:launchMode="singleInstance" as well.

Need to Hide information in an activity or a fragment when app running in background

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);

android app running multiple instances

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.

Android app auto destroyed after 75 seconds

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?

Android forcing full restart after an app is killed

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.

Categories

Resources