如何在另一个应用程序执行的后退按钮的动作? [英] How to perform back button action in another app?

查看:149
本文介绍了如何在另一个应用程序执行的后退按钮的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想简单的应用程序,以杀死在当前可见的活动堆栈中的活动......如何实现应用程序在后台和关闭活动,正在运行的应用运行?

i want simple app to kill the activity from the stack in current visible activities... How to implement the app to run in background and close activities in running apps?

推荐答案

假设这些都是你自己的活动,你需要声明你想成为可关闭该活动的动作,然后调用从其他应用程序,采取行动。闭幕活动将在得到通知<大骨节病> onNewIntent()在这里你可以检查行动,并呼吁完成

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

在关闭的活动:

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

在可关闭的活动mainfest

In closeable activity mainfest

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

在其他活动

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

这篇关于如何在另一个应用程序执行的后退按钮的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆