Already launched Activity is not displayed in front when launching Intent - android

that's the second question concerning my custom Android launcher project.
This time, I encountered a problem opening Apps. It only occurs, when an App is already opened and therefore in the history.
E.g. if I open the Settings App and after that the Facebook App, both of them appear in the history. When I try launching the Settings App again, it just shows me the Facebook App.
Here is the source code of the Launching Intent. ActionName ist the PackageName of the ApplicationInfo.
Intent launchIntent = activity.getPackageManager().getLaunchIntentForPackage(actionName);
launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
//launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
// Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(launchIntent);
I tried all imaginable Flag-Configurations. Not just the ones you see in the code sample. (REORDER_TO_FRONT,...) Maybe I missed one.
Thanks in advance!

Related

Ignore FLAG_ACTIVITY_CLEAR_TASK on android.intent.action.SEND

I'm trying to have other apps share PDF files with mine, I have an intent filter for android.intent.action.SEND type pdf files but some apps send the intent with the FLAG_ACTIVITY_CLEAR_TASK which closes the activity that was already running.
Is there any way to ignore this flag? I want to keep the current activity running when shared to my app.
EDIT: a good example
I share a PDF with google drive pdf viewer, my activity that is already running picks it up and the intent is received in "onNewIntent" (desired).
When I do the same thing with Samsungs "my files" my activity gets restarted and the intent is given to "onCreate" (not desired)
I share a PDF with google drive pdf viewer, my activity that is already running picks it up and the intent is received in "onNewIntent" (desired).
When I do the same thing with Samsungs "my files" my activity gets restarted and the intent is given to "onCreate" (not desired)
Your app should work correctly regardless of how it's invoked. What difference does it make to you whether it's a new instance receiving the intent or the existing one? You're not always going to have an existing instance around, right? If you share from Google before starting your activity, you'll be in the same position, won't you?

How can I auto install programmatically app without start Intent.FLAG_ACTIVITY_NEW_TASK

In fact, I want to be noticed when the program is downloaded without the user having to install their own apps (Install without show permissions activity).
Now I use the following code, and I want to change this code to answer my question.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The following image is displayed after downloading the app from my server and i dont want to show

Bring the app to foreground and if it is already running rather than creating new instance of it in android

In my app I want to launch apps(messaging,contacts,etc)if my launched app(messaging,contacts,etc) is already running in background I want it to bring front.I tried using moveTaskToFront() but it doesn't implement from above API 23(Lollipop).So,I ended up with this code:
Intent intent=getPackageManager().getLaunchIntentForPackage("com.android.mms");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
By using this code if I launch a messaging from inside my app it launches,and if I again launches the same app from inside my app it perfectly resumes it and continue from where we left it.
But when I Launches the same messaging app from my default android launcher it just create new instance of messaging app on above of my already running messaging app which was already launched by my app.
I don't know what the solution for this.Please help me ...
Use the below approach to invoke intents within your app like this.
Intent intent = new Intent(CONTEXT, TARGET_ACTIVITY.CLASS);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Proper flags to start an activity from a launcher

I have an application that starts the app selected by a user when it is clicked (like a launcher would). Note however that the actual starting of the app is performed by a service because of abstraction.
One note by a user:
Launching greader from your app opens greader as if it had never been used, prompting for account details etc regardless of whether they have been entered previously. Launching greader from any other method (nova laucher app drawer) gets me to my usual newsfeed.
Other users are reporting issues with root explorer crashing when started.
My best bet is that is has something to do with the launch flags. After investigating the default android launcher, my conclusion is that I am using the same flags.
These flags are: Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
What flags should I be using instead? I would not prefer to add exceptions for certain apps, so the flags should work for all apps to be started.
Thanks for any help
The problem was not with the flags themselves, they were just fine. This issue was with the action not being set properly. The problem was solved by initializing the intent like this:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

Launching Android Market Main Page from an application

I'm trying to write a launcher-like application (I'm not planning to release it, it's just for me to use) but I don't seem to find any way to launch the Market.
All of the answers I've found actually perform a search on the Market (using a uri "market://") or even worse they run the Market on a specific app page, while I'm trying to show the main page of the Market, i.e. the page shown when you run it from the launcher.
I tried using just "market://" as a Uri, without query strings, but it doesn't work; I also tried to get exactly the same "signature" of the "start activity command" that appears in the LogCat when I run the Market from the Launcher (by manually editing component, flags and categories), but it still doesn't work.
Is there any way to get it to show the main page?
Thanks in anticipation.
Intent intent = new Intent();
intent.setClassName("com.android.vending", "com.android.vending.AssetBrowserActivity");
startActivity(intent);

Categories

Resources