0

I have searched and found many related questions:

How to leave the current app and launch an activity of another app?

Launch another application INSIDE an application in Android

I have this code that works to just launch the app:

Intent intent = new Intent(Intent.ACTION_MAIN);
PackageManager managerclock = getPackageManager();
intent = managerclock.getLaunchIntentForPackage("app_package_name");
startActivity(intent);

But they all OPEN the launched app, bringing it to the foreground, and sending my main (launcher) app to the background.

I want to launch the new one, but keep it in the background, and stay in the main one. Any tips?

NOTE: Second, I would like to press a button on the first/welcome screen of the launched app (which has a specific label, that i know), all while keeping it in the background and staying on the main app. Is that possible?

Frederik
  • 33
  • 9
  • 1
    "But they all OPEN the launched app, bringing it to the foreground, and sending my main (launcher) app to the background." That's the normal behavior. You cannot start some other app's Activity and have your own app remain "in front of" the started Activity. About the second question: *if* you could somehow make the other app stay in the background, you could certainly not interact with its UI. As soon as the app's UI is accessible to user interaction, it is as much in the foreground as it can get. – Bö macht Blau Jan 24 '20 at 18:05
  • NO, its not possible, yes if you startActivityForResult then its possible – Rushikant Pawar Jan 24 '20 at 18:51
  • What exactly are you trying to do? What does launching an app mean if you don't show it to the user? – Ryan M Jan 24 '20 at 21:53
  • to @RyanMentley:By "lauching app" I meant the main one, which I am developing, and which should stay open in the foreground. From this app, I want an instruction to be given to "launch" another app, but have it stay in the background. I want to keep in the background because it does only one function, which is necessary for the main/launching app, but the user doesnt have to see it. – Frederik Jan 27 '20 at 09:26
  • to @RushikantPawar: I will do some research about startActivityForResult, but could you specify a bit more what could be done? – Frederik Jan 27 '20 at 09:27
  • 1
    You may be looking for a [service](https://developer.android.com/guide/components/services) – Ryan M Jan 27 '20 at 09:28
  • to @0X0nosugar: thank you for your answer. I am still hoping there is a solution or some other way around it - maybe the 2nd app being launched but automatically sent back to background, without the user needing to do anything? – Frederik Jan 27 '20 at 09:29
  • @Frederik, If the water is available, and the glass in only one and if we both are thirsty, can we drink water at the same time with the same glass? i have to give glass to you ( you comes in foreground and i goes in background ) you finish drinking water and gives glass to me ( you goes in background and i comes in foreground ) – Rushikant Pawar Jan 27 '20 at 09:49
  • @RyanMentley: I am looking into it. What the 2nd app does is a foreground service in itself, I think, because it displays a notification. Ideally I would know how to code what the 2nd app does and run that service in my main app - b ut I since I dont I was trying to find a solution. How could I use a service in the main app to launch silently the 2nd app? – Frederik Jan 27 '20 at 10:02
  • @RushikantPawar: Ok, I get the message there. Thank you for the attention and time. – Frederik Jan 27 '20 at 10:02
  • @RyanMentley: we're trying out the service option. It opens up a lot of other capacities in and Android app - thank you for the tip. – Frederik Feb 10 '20 at 17:57

0 Answers0