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.
Related
Scenario :
In my application i have enabled app linking. So when an App link is triggered, i have set a dummy AppLinkActivity (opens as "singleTask" to avoid creation of new task) to receive and handle the url received through the app link. While handling the url, i have to check whether the app was showing the "DownloadActivity", if so then i have to show a dialog.
So when an App link is triggered, i will have the already existing task with existing activities and on top of that will be the AppLinkingActivity. In this case i have no way to know what the previous activity was, since i cannot pass anything via an intent.
What i want to do
When the AppLinkingActivity is opened via an app link, is there any way by which i can find out what was the last shown activity(of my app) before AppLinkingActivity in the same task?
--Alternatively--
If i exclude the "singleTask" in manifest then the AppLinkingActivity is opened in a new task. In this scenario, is there any way by which i can get the last shown(or topmost) activity in the previous task? If yes, i also need a way to navigate to that topmost activity in the previous task? In this scenario if i simply finish() AppLinkingActivity, then the control goes back to the which ever source that triggered the app link like browser or gmail app etc.
Is any of the above two requirements is possible?
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.
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 .
I am trying to open a PendingIntent that opens the Gmail App in the background through a notification.
The steps are as follows:
Show notification with action button
On click of action button (which has a PendingIntent), I want start the PendingIntent (which launches the Gmail app) but in the background.
Dismiss Notification
The notification remains the only thing that the user has seen (i.e. the UI has not changed but only the notification has itself been dismissed after clicking the action button).
It may be "hack-y" but I could also quickly open and then "minimize" the gmail app?
Any ideas?
OK, I really don't understand what you can achieve from such behavior.
you definitely could not provide any meaningful extra data on the intent (unless you are the developer of gmail, which I don't believe is the case..).
actually, if you provides intent to launch explicitly Gmail app (by specifying the package name) - your code would break if Gmail app package name would change.
now to your question:
it is possible to launch activity without bringing it to foreground:
all you have to do is add to the intent been held by the pending intent to flags: FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_MULTIPLE_TASK
FLAG_ACTIVITY_MULTIPLE_TASK flag is not recommended for use unless your application is the launcher.
gmail main activity would create in background new task, and that's it.
note that the gmail activity would not go threw the onResume and onStart callbacks (because it's not on foreground..) , so if any meaningful code happens from this callbacks - they won't be executed anyway..
UPDATE
now that I know that your purpose is to mark an emails as "read", I can tell you that any attempts to launch gmail app want do to you any good. as I mentioned, you can't pass extra meaningful data to gamil launching intent. there is simply no such API's, and launching main activity simply won't do anything that would help you.
instead, I'll suggest you to use Gmail API's for control user's inbox
I'm writing a basic application. One of the features I'm interested in trying to do is to launch another app, INSIDE the app already running.
Eg. I have an app with 3 menu options, 1 and 2 do certain tasks as part of this parent app, menu option 3 launches another app that's installed on the phone.
I'm not sure if this is possible?
This is possible with the Intents mechanism.
The exact Intent you'll have to write depend on various factors:
do you have to provide some data to the launched application?
do you target a specific application or do you want to let the user choose the application he prefers for that task (in case he has several applications able to do what you need)?
do you want to ensure that the application is available? (that would be better)
do you know if the other app provides specific intent-filters to do some tasks?
Edit:
Then, you should be able to start the second application with the following code:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setPackage("com.otherapp.package");
startActivity(i);
Place this code in the OnClickListener of your button and that should be enough.