Search code examples
androidandroid-activitytaskaffinity

When taskAffinity activity is calling finish() but it is not dismiss recent apps


I have taskAffinity activity which is BActivity and AActivity is a normal activity.

AActivity is calling BActivity by using below startActivity function. When BActivity's jobs have done, BActivity called finish(); function but BActivity doesn't dismiss recent applications.

startActivity:

Intent intent = new Intent(AActivity.this, BActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Where am I doing wrong?

AndroidManifest:

          <activity
            android:name=".BActivity"
            android:excludeFromRecents="true"
            android:exported="true"
            android:launchMode="singleTask"
            android:taskAffinity=".AActivity">
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
          </activity>

          <activity
             android:name=".AActivity"
             android:configChanges="locale"
             android:screenOrientation="portrait"
             android:windowSoftInputMode="stateHidden|adjustPan" />

Solution

  • Try to use for upper SDK 21

    finishAndRemoveTask();
    

    and lower 21 use

    finish();