I know this question is common and asked many times on Stack Overflow, but after visiting nearly the four pages of search engine results and nearly the 20 question of Stack Overflow regarding this issue, I found that none of them is resolved or answered correctly.
What I want:
I want to show my app in recent apps list when it is running but when I close app then my process should be killed and application should be removed from recent apps list.
Some answers I found:
use System.exit(0); //doesn't clear app from recents
OR
use android.os.Process.killProcess(android.os.Process.myPid()); //doesn't clear app from recents
OR
use finish() or this.finish() or Activity.finish();// doesn't clear app from recents
And one common suggestion I see in every answer that add below code in manifest:
android:excludeFromRecents //I think this is wrong approach.
because after adding this when user presses home button while my app is running then user cannot see my app in recent Apps List.
And many other suggestions on this but none of them do both tasks close application and clear application from recent apps list. Also if you go in Settings>Apps>yourApp>your Application
see that still it asks for "force stop" means application is running!