[英]How to come back to the Application that launched my application
Background: 背景:
My app (I will call it " A ") can be started from an intent. 我的应用程序(我将其称为“ A ”)可以从一种意图启动。 If a specific URL is clicked A is opened.
如果单击特定的URL,则打开A。
A has a custom navigation, so the back button does not always override super.onBackPressed() or finish() it. A有一个自定义导航,所以后退按钮并不总是覆盖super.onBackPressed()或完成()它。
The problem: 问题:
After opening A from another app lets say the email app (I will call it " E "), A can not come back to E . 从另一个应用程序打开A后 ,可以说电子邮件应用程序(我将其称为“ E ”), A无法返回到E。 If I click the "tasks" button, where the user can see the name, icon, and a thumbnail of the current running apps, I can see that E (icon and name) has as thumbnail A , not E .
如果单击“任务”按钮,用户可以在其中看到名称,图标和当前正在运行的应用程序的缩略图,则可以看到E (图标和名称)的缩略图为A ,而不是E。 When I click on it I go to A , and cannot come back to E .
当我单击它时,我转到A ,而不能返回到E。
The question: 问题:
Is there a way to come back to E from A ? 有办法从A回到E吗? Should I track the activity stack to come back to it whenever I want?
我是否应该跟踪活动堆栈以在需要时返回到活动堆栈? I know that I can not force close an application, but could I open the A from E closing E before A is open?
我知道我不能强制关闭应用程序,但是我可以在A打开之前从E关闭E来打开A吗? Is there a way to specify this behaviour on the intent?
有没有办法在意图上指定此行为?
Thanks in advance. 提前致谢。
I found a solution that is working. 我找到了有效的解决方案。
I check if the Activity of A comes from E , in this case I clear the Activity Stack and relaunch A . 我检查A的活动是否来自E ,在这种情况下,我清除活动堆栈并重新启动A。
if(comesFromE()){
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
This answer helped me: howto programatically “restart” android app? 这个答案对我有帮助: 如何以编程方式“重启” Android应用程序?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.