简体   繁体   English

如何在另一个应用程序中执行后退按钮动作?

[英]How to perform back button action in another app?

我想要简单的应用程序从当前可见活动中取消堆栈中的活动...如何实现应用程序在后台运行并在正在运行的应用程序中关闭活动?

Assuming these are your own activities, you need to declare an action on the activity you want to be closeable, then call that action from the other app. 假设这些是您自己的活动,则需要对要关闭的活动声明一个动作,然后从另一个应用程序调用该动作。 The closing activity will get notified in onNewIntent() where you can check the action and call finish 关闭活动将在onNewIntent()中得到通知,您可以在其中检查操作并完成调用

In closable activity: 在可关闭的活动中:

   @Override
   protected void onNewIntent(Intent intent) {
       super.onNewIntent(intent);
       if ("action.action.myactionstring".equals(intent.getAction())) {
           finish();
       }
   }

In closeable activity mainfest 在封闭活动中

   <activity android:name=".CloseableActivity" >
        <intent-filter>
            <action android:name="action.action.myactionstring" />
            ...
        </intent-filter>
   </activity>

In the other activity 在其他活动中

    Intent intent = new Intent("action string");
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(intent);

Did you try finish(); 您是否尝试了finish(); Command? 命令? More Info 更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM