Reputation: 3675
I am looking for a way to launch another app from within my app but so that the focus is not changed from my app to the app launched.
I.e currently I have the new app launched via a intent, however when this is carried out the new app is launched and becomes the app in view, I need it to be kept in the background with my app still in view.
The reason for this? I am developing an application for internal use that will act like a lock-screen to the device so although things must happen in the background the 'lock-screen' must always be on top.
I have done some research into intents and launching other apps but can not find anything about what I need.
Hope you can help thank you!
Currently the terminal is called like this:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("jackpal.androidterm", "jackpal.androidterm.RemoteInterface"));
intent.setAction("jackpal.androidterm.RUN_SCRIPT");
intent.putExtra("jackpal.androidterm.iInitialCommand", cmdString);
The reason it needs to be running in the background is so that the app can run commands in terminal without the user having access, but then they 'unlock' the screen they need to then be able to view the terminal and what commands are being run etc
Upvotes: 4
Views: 7174
Reputation: 136
In addition to the answer from @Meher, in the intent for your current starting activity, you can add the flag FLAG_FROM_BACKGROUND. With this you get rid of the "blinking" effect (the one where your activity shows for one fraction of second while it discovers wether to go to background)
Upvotes: 1
Reputation: 2585
You can not startActivity in Background.Instead start the activity and minimise the activity(in your case this activity is of different application) using moveTaskToBack(true);
In your case, put a condition based on your intent and its params and use moveTaskToBack(true);
so that activity will be minimised only when your application launches.
Upvotes: 2
Reputation: 2738
This won't be possible, you will have to start a background Service
that does the actual work and only launch the Activity
you want to navigate to once your foreground Activity
is finished. Depending on your architecture, you can store the Activity
to call when your foreground Activity
is finished and change it from the service. That way you will have your desire behaviour without having to actually call the Activity
.
Upvotes: 1