简体   繁体   English

如何返回启动我的应用程序的应用程序

[英]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.

相关问题 如何在android中的ACTION_CALL之后回到我的应用程序 - how to come back to my application after ACTION_CALL in android 如何检索启动了我的应用程序共享意向的应用程序名称? - How to retrieve the application name that launched a share intent to my application? 如何处理从我的应用程序启动的应用程序 - How to manipulate the application that I launched from my application 如何终止从我当前在android中启动的应用程序? - How to terminate an application which is launched from my current application in android? 如何在应用程序启动后立即为我的应用程序启用辅助功能设置 - How to Enable Accessibility Setting for my application as soon as the application is launched 离开应用程序后如何回到同一个片段 - How to come back to the same fragment after leaving application 按下主页按钮后如何返回到应用程序 - how come back to Application after pressing home button 如何使我的android应用程序在启动时启动然后隐藏 - How to make my android application launched in the boot and then hidden 找到哪个应用程序启动了我的Activity - Find which application launched my Activity 我的应用程序一启动就停止工作 - my application stops working as soon as launched
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM