1

Below is sample app for testing excludeFromRecents attribute of activity(it's just generated by studio)

And accoding to https://developer.android.com/guide/topics/manifest/activity-element, MainActivity should not shown at recent list. but it's not working.Anybody know why?

I tested with launchMode, with two activities, noHistory(it's delete task with animation, but this isnt what I want, it should not shown from first), autoRemoveFromRecents(this works well for only finished activity, not ongoing activity). But result was same.

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme">
    <activity android:name=".view.MainActivity"
        android:excludeFromRecents="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main_activity)
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.sample.myapplication"
        minSdkVersion 29
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
woosuk
  • 191
  • 2
  • 11
  • How did you launch the app for the first time? From the installer? From an IDE (Android Studio)? If so, please kill the app (settings->apps->Your App->force stop) and then launch it again from the HOME screen. See if it now exists in the recents list (it should not). – David Wasser Aug 30 '20 at 20:31
  • Thanks but..Result is same Actually sometimes it works well(I dont know exact route) but most of the time it's not... Launching from IDE and home screen, What's the difference? – woosuk Aug 31 '20 at 00:45
  • You might be seeing this nasty Android bug: https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508#16447508 Does this happen on all devices? Specific devices? Emulator? – David Wasser Aug 31 '20 at 06:06
  • I checked at several devices including PIXEL – woosuk Aug 31 '20 at 07:14
  • Sounds very strange. This should just work. I don't see why it wouldn't. If you can figure out the difference between when it works and when it doesn't, let us know. – David Wasser Aug 31 '20 at 08:44
  • Thanks for your help. below is what I am said https://github.com/woosuk0410/ExcludeFromRecentsTest – woosuk Aug 31 '20 at 11:21
  • Please try overriding `onPause()` in your `Activity` and call `super.onPause()` and then call `finish()` and see if that helps. – David Wasser Aug 31 '20 at 12:47
  • Thanks for your help but .. finishing at pause is same as android:noHistory attr option. It makes animation at launching recent task list. And App needs to alive at onPause. – woosuk Aug 31 '20 at 13:28
  • Why do you not want the app to appear in the list of recent tasks? – David Wasser Aug 31 '20 at 14:13
  • Its customer's requirement. And according to docs, it should be possible – woosuk Aug 31 '20 at 15:30
  • Yes, I'm just asking why. "It is customer's requirement" isn't a reason. The question is "why does the customer want this?" The reason I ask is that if you want to obscure the view from the list of recent tasks for security reasons, there is another way to do this. Usually if you remove your app from the list of recent tasks this can confuse the user, so you don't want to do that unless there is a real reason. Often there are other ways of getting what you want. – David Wasser Aug 31 '20 at 16:33
  • Anyway, just tested on my device. Works fine. When you press HOME the app is no longer in the recents list. Even if you launch the app and then press the RECENTS button without first pressing HOME then it doesn't show up in the list. This is the way it should work, so you've got something strange going on. Please add your `build.gradle` file to the question. – David Wasser Aug 31 '20 at 16:49
  • My app is launcher app so I need to control these features. I updated build gradle. but there's nothing special. What is "other ways of getting what you want" that you said. And is that working well on your side? – woosuk Sep 01 '20 at 00:36
  • Read this: https://stackoverflow.com/questions/43274289/android-customizing-recent-apps-thumbnail-screenshot-by-default – David Wasser Sep 01 '20 at 07:33

1 Answers1

1

self answer

"android:excludeFromRecents" removes task only in case of home button -> recent button

In case of directly recent button, tasks remain at list

woosuk
  • 191
  • 2
  • 11