Android Question get the focus back

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
a few years back i asked that question and Erel replied
now i need to refine the question as the entire situation changed

here is the scenario

- my app loads and run
- there's a case where it will need to call another app
- when the second app finish its task it does not close and stays on screen waiting for its normal flow
- i got the result that i want from 2nd app and now i want to take back the focus and continue

how do i get back the focus?

thanks
 

zed

Well-Known Member
Licensed User
You cannot close another application from within your own (an Android restriction).
The best practice is to restart your activity or use "StartActivityForResult" so the system handles the return.
If the other application isn't designed to return a result, you'll simply need to bring your app back to the foreground using "Intent" or "BringToFront".

This should bring your app back to the foreground.
B4A:
Dim in As Intent
in.Initialize("", "")
in.SetComponent("com.votrepackage/.Main")
StartActivity(in)

If the other app supports returning results, use "StartActivityForResult(in)". When the other app finishes, Android will recall your activity with the result, and your app will automatically regain focus.

You can also use "Activity.BringToFront".
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
You cannot close another application from within your own (an Android restriction).
The best practice is to restart your activity or use "StartActivityForResult" so the system handles the return.
If the other application isn't designed to return a result, you'll simply need to bring your app back to the foreground using "Intent" or "BringToFront".

This should bring your app back to the foreground.
B4A:
Dim in As Intent
in.Initialize("", "")
in.SetComponent("com.votrepackage/.Main")
StartActivity(in)

If the other app supports returning results, use "StartActivityForResult(in)". When the other app finishes, Android will recall your activity with the result, and your app will automatically regain focus.

You can also use "Activity.BringToFront".
thanks
i will try that

BTW - i do not wish to close the 2nd application just to get the focus back
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
BTW - i do not wish to close the 2nd application just to get the focus back
I'm not sure it's in your hands. As I understand it, (for normal cases) the OS decides freely when to kill background apps.

I'm curious, what are you trying to achieve when you offload a task to a separate app? What is the task? Is the second app made by you?
 
Upvote 0
Top