How to perform back button action in another app?

你说的曾经没有我的故事 提交于 2019-12-12 01:44:54

问题


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?


回答1:


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

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);



回答2:


Did you try finish(); Command? More Info



来源:https://stackoverflow.com/questions/21351974/how-to-perform-back-button-action-in-another-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!