I think we have three apps, and all of them are open and we know the process name. How can I switch from one app to another app, also keeping in mind that another app has opened a intent, and I do not want to go to another app with opening an app launcher, just switching or making another app at front.
I want to make another app on front, for example if Internet is background, I make it at front.
Make the main activity for your applications singleProcess, if the application is already running it will be bring to the front. you can also, implement a custom BroadCastReceiver to start the application using its package name.
Related
I have an app that acts as sortofa bridge between two other apps, A and B, both of which are mostly black boxes. The user almost always stays in app A but sometimes needs to do something that my app or app B know how to handle. App A supports external actions via URL so I have a custom scheme://host defined for my app.
If the user does an action that my app handles, I get launched via the URL then do my thing then call finish() and the user's back in app A where they started (edit: same activity and etc) - perfect.
If the user does an action that app B handles, my app needs to be in the middle so it can do some translation. App A launches me, I format the message for app B and launch it. When it's done and comes back to my app, I call finish() and.. end up back in app B. Understandable I guess but I really want to end up in app A.
So the question is, how to I tell Android to put A back on top/in front without changing it? I can find the URL for app A via getReferrer() but when I put that into an Intent, it acts like I'm restarting app A instead of just going back to where it was. The doc for Intent.FLAG_ACTIVITY_NEW_TASK looked promising but it still acts like a new instance of the app.
It seems like this should totally be possible but I'm not seeing it. Java/api25.
The problem is that App B is not ending, returning control to your app. App B is launching your app, putting your app on top of it. When your app finishes, your app goes away revealing the still running App B underneath.
So basically App B has bad behaviour (at least, behaviour that is inappropriate for what you are trying to do).
To solve the problem you can either fix App B, or you can do the following:
Instead of just calling finish(), when you want to return to App A just launch it the same way that Android launches an app when the user presses on the app icon:
Intent intent = getPackageManager.getLaunchIntentForPackage("package.name.of.app.A");
startActivity(intent);
finish();
This will bring App A to the front in whatever state it was in when it was put in the background (ie: doesn't actually launch any new Activity). If App A isn't running, it will launch the root Activity of App A, as if the user pressed the app's icon on the HOME screen.
I'm assuming that both App A and App B are running in separate tasks. If that isn't the case, I'll need you to provide more information about which activities are running in which tasks.
I have implemented a splash screen for my app. I made the splash screen activity the launch activity. The splash activity does the startup work (loading data, etc.), and then launches the "real" main activity.
The problem is this: I am using a 3rd party app that has the ability to launch other apps. Let's say my app is already running (it is past the splash screen, and is on to the real main screen). I then press the Home button to put the app in the background. I then do something that causes the 3rd party app to launch my app. What I want is for my app to be simply restored (as it would if I had tapped the app icon from the phone's regular launcher). Instead, it launches the splash screen all over again, and my initialization code runs again, which I don't want.
Since this is a 3rd party app that is starting my app, I don't have the ability to change how it launches my app. I am assuming that it is just querying the package manager to get the launch intent and starting that. So, I need to find a way to fix this in my app itself.
Is there a way that I can find out from my splash screen's onCreate method if my "real" main activity is already running, and if so, skip the initialization code and bring the existing main activity to the foreground?
Keep a static boolean in your Application class.
When initialization is done, set it to true.
When splash screen starts, check the value of the boolean, if true, go straight to your main activity without doing any logic, and instantly finish the splash activity.
If false, then assume it's a cold start and you need to run the initialization code.
There is no way to look at the Activity stack from within an Android app, so you can't check if the Main activity is already running.
There is also no way for the 3rd party app to check if your app is running, and then launch a different activity depending on that.
Is it possible to close an activity which hasn't been started by your activity?
So, suppose I have an app which has MainActivity. My Mainactivity wants to close CNN app that is installed on my phone (and probably running in background). Is it possible?
To do that, you'll either need to have a rooted phone, OR, have created the other application yourself (so you could write code to close itself down when getting a specific broadcast)
Seeing as you want to close the CNN app, which im guessing you haven't created yourself, then no, it's not possible.
An application can't simply manipulate other applications lifecycle.
Mostly no. Because of android security model you cannot have direct access to third party activities data/methods. You could only close 3rd party activity via intent in this activity will support this kind behaviour.
Is it possible to run an application from inside another application? What I want to do is write an app which allows you to chose an app to start, and then displays the activities of this app inside a view.
So in landscape mode, it should look something like this:
The idea behind this is:
I want to be able to start and run a third party activity next to my own activity, and I want to be able to create individual makros with my activity that are controlling the third party activity.
Basically, something like this:
Start third party activity from inside my app
Start makro recording
Do something in third party activity
Stop makro recording
Use makro whenever you wish
So how can I start and control another activity from inside my own activity?
Unrooted:
Sadly, what you want to achieve does not seem to be possible without rooting the phone, because you can only interact with other apps via intents. Since developers decide how their apps react on specific intents, creating macros this way is nearly impossible.
With rooted phones:
You may want to create a list of all installed apps, you can use
getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
to retrieve a list of all installed apps.
If the user now selects an app, launch it via an intent and create a system overlay to get all touch/key events (and let the user stop the macro). You can find a way to do this here. Store the x/y-values of the touch-events.
You can recreate the events using MotionEvent#obtain.
Now comes the part where you need a rooted phone (the permission INJECT_EVENTS). Launch the app and inject the events so your macro gets executed. Samplecode:
Instrumentation m_Instrumentation = new Instrumentation();
m_Instrumentation.sendPointerSync(motionEvent);
You can find more information about injecting (also keyevents) here.
If you need help to compile your app, these 2 links will help you: How to compile Android Application with system permissions, Android INJECT_EVENTS permission
It's not possible to start an application in a View, but you can launch an app from within your app:
Intent i = getPackageManager().getLaunchIntentForPackage("com.package.ofapp");
startActivity(i);
//EDIT to your updated question:
After starting the activity from the above code, one way you could start/stop the macro at any time in the new app would be to create a small view overlay on top of the screen.
This overlay would be on top of ALL activities.
Check out the following link: Creating a system overlay window (always on top)
You could write code to start the macro when the View is pressed, and then if the button was pressed once and the user presses it again, stop the macro. This would be in the onTouchEvent() method.
Yes, I think it's possible as a app named floating apps does that (WITHOUT ROOT)
Only using some adb commands
https://play.google.com/store/apps/details?id=com.lwi.android.flapps
Yes its possible if you use Intents. They allow you to move between screens and to launch another different functionality inside the same app. visit coursera for more tutorials on intents
i just want to know how can i detect if the user opens an app so an activity of mine launches as well.
For example, the user opens the sms app and right after a kind of lockscreen appears.
You can create a service which will run int the background and you can use this API to determine which activity is visible. That's how many app lock works.
As far as I understand the Android system, it is not possible unless you are making a custom firmware.