Bring third party app to the front - android

i'm trying to bring a third Party app to the front if it is on stack..
This is the best Approach i was able to find, but it is not working well regarding to the comments under the first answere..
How to bring most recently used third party Activity to front?
The common Approach is an Intent:
Intent myIntent = getPackageManager.getLaunchIntent("packageName of third Party app");
startActivity(myIntent);
this works in some cases.. but not in all.
So i tried to set the right flag regarding to the Android docs:
myIntent.setFLags(Intent.FLAG_ACTIVITY_NEW_TASK);
FLAG_ACTIVITY_NEW_TASK:
When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in. See FLAG_ACTIVITY_MULTIPLE_TASK for a flag to disable this behavior.
Issue stays the same. There must be a way, because OS is doing this everytime you click on the Icon of the app which is already on the stack.. it brings the current Task to the front for every app..
So, is there a way to bring the current Task to the front of every third Party application i want to? Or is just the OS allowed to do so?
Any help is appreciated.

Try the following..
Intent intent = getPackageManager().getLauncherIntentForPackage("thirdPartyPackageName");
startActivity(intent);
I have tested this with 4 different third party applications.. It works fine .

Related

How does this code to move the app to the background work?

I wanted a way to exit my app. Hence I searched and found a piece of code which does that.
But I am not able to understand the code and why it does what it does.
Can anyone please explain?
Here is my code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
It's starting the action ACTION_MAIN that has the category CATEGORY_HOME. This corresponds to:
This is the home activity, that is the first activity that is displayed when the device boots.
So, this means the launcher. So, this is a fancy way of starting the launcher app.
Also, the flag FLAG_ACTIVITY_NEW_TASK means it will be started on a new task, not the same as your app is running.
Notice that this will not finish your app, it will just put it in the background (like switching to another app using the task switcher, just this app happens to be the launcher). The effect is the same as pressing the home button.
Also notice that if the user happens to have two launcher apps, and it has not selected the default one, it will get a chooser asking to select which one of the two (or more) apps wants to use. Not the best experience.

Android completely force quitting an app

I have a login activity. After login, the Main activity is started, which uses fragments for user navigation. I want a button in the nav drawer of my main activity which will completely close the app
Now, I have seen many many threads on this and have tried implementing their solutions. For example:
I have tried finishAffinity() in my Main activity, which should close the current activity as well as all parent activities
I have tried using finish() on the Login activity as soon as I bring up the Main Activity, and then calling finish() again when the user clicks the button
The highest voted answer for this question: Close application and remove from recent apps/, also does not seem work. First, android:autoRemoveFromRecents="true" requires API > 21, but even if I set the minimum SDK version to 21, the app still remains in the list
Finally, I have tried using an Intent when the user clicks the quit button and navigating back to the Login activity, and setting flags with an exit extra, and then finishing the Login activity (i.e. exit android application programmatically)
None of these are working. They will all close the Main Activity, and maybe even close the Login activity. But if the user clicks the app list/current apps/open apps key (the square soft key on most phones), the app is still visible there. When the app is clicked in that list it will take me back to the Login activity screen (I'm unsure if this is starting the app from fresh, or whether its just taking me to the previous Login screen which didn't close)
Out of desperation I have even tried System.exit(0), which I know is bad, but even that doesn't remove the app from the app list
So, how do I programmatically completely quit an app and remove all traces of it being open?
EDIT: I was too hasty in claiming one of the answers below didnt work (see italics above). The answer does remove the app correctly
I think this is the solution you're looking for.
You might consider having another activity named ExitActivity which will be called when you try to exit from your application. The trick here is, the ExitActivity will have android:autoRemoveFromRecents set to true in the manifest file, so that your instance will be cleared automatically from the recents.
Based on my research:
There is no way to force quite an application in android. You can only pause an activity. The discretion to quit an app lies totally with android framework which it does on checking the memory and resource utilization of apps. I could not find the official link for now, but I had read it earlier.
manage it by the OS. bring up the home screen.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Android startActivityForResult hide screen shot

In Android, I call startActivityForResult to start another activity, which is an email intent, and I also want to hide the screen shot for this new activity from Android task manager.
I know usually use Window.AddFlags(WindowManagerFlags.Secure) before SetContentView of Activity, but for the new activity from startActivityForResult, how to setup such flag?
Thx
which is an email intent
I am assuming that you mean "an Intent that will resolve to some third-party activity that happens to involve email".
I also want to hide the screen shot for this new activity from Android task manager
You are not the author of the other app. The decision of whether the other app should appear or not appear in the task manager is up to the developer of the other app, not you.
If you need this degree of control, do not display any activities from third-party apps.

android exit application completely and go to main applications screen

i know that this question is asked many times, but really i can't understand the answer, i want to set button, when user click it i want to exit the application (also the carbage collector should remove the objects), and after exiting i want to go to the screen where the user found the application icon on mobile.
for exit i don't know what to do
for going to the screen where to find the application icon i tried like this
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
but doesn't work
use this method, this will make your application to go in backgroud and will open home/app_menu screen
moveTaskToBack(true); // method available in activity
reference link
When you start that activity, it will effectively stop your application's foreground activities. Android is designed to NOT shutdown the app so that it may be restarted faster.
However, if you really really want to purge the app from memory, then what you want to do is kill exit() on the Runtime singleton : http://developer.android.com/reference/java/lang/Runtime.html#exit(int)

Clear the activity stack before launching activity with intent

I'm working on C2DM notification for an Android Application and I'd like to open my application when user click on the notification. There is no problem for that, this is pretty easy.
The problem is that when the application is launching (after clicking on the notification), if some activity was previously opened, the launched activity seems to be added to the actual activity stack, what is a problem regarding to the complexity of my application (there is a lot of activity, some with static fields).
To solve the problem, 2 solutions would be OK:
1) Do not call a specific activity but just ask to my application to open (like when I click on the application icon on the home screen: Open the first activity if the application was closed or just bring the application to the front if was opened (but was in background)).
2) Clear all the activity stack and launch a specific activity.
But I didn't succeed to do one of both solution. Even using intent flag (like http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP).
Can somebody help me to solve this problem?
Thanks
PS: Sorry for my poor English, I'm from Belgium :-)
It's not what you asked to do but you can add the attribute android:launchMode="singleTask" to the activity you will be calling out of this notification and it won't create a new activity if one this instance already exists.
You could possibly also use the ActivityManager.killBackgroundProcesses(String packageName) to remove background processes but I have never tried this and it isn't advised or use the ChriZzZ suggestion and manage your activities a bit tighter.
Sounds like you are searching for FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
If set, this marks a point in the task's activity stack that should be cleared when the task is reset. That is, the next time the task is brought to the foreground with FLAG_ACTIVITY_RESET_TASK_IF_NEEDED (typically as a result of the user re-launching it from home)

Categories

Resources