Question

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?

Was it helpful?

Solution

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

OTHER TIPS

Did you try finish(); Command? More Info

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top