In this video it shows the difference between the two APIs in Android – finish() vs finishAndRemoveTask().
finish() is basically to minimize the App’s view so that the user cannot see the App’s layout anymore. It is similar to pressing back button from App’s home page to go back to Android OS screen.
finishAndRemoveTask() is similar to finish(). However, in addition to the functionality of finish() it also removes the App’s task from the Android OS task manager. Hence, the App is no more accessible and cannot be resumed from the task manager. The only option for the user is to restart the App using the App’s icon click.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
package com.programmerworld.finishandremovetaskapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonFinish(View view){
finish();
}
public void buttonFinishAndRemoveTask(View view){
finishAndRemoveTask();
}
}
No changes in any other artifacts of the project such as Manifest file or gradle files.
Task from the task manager as show in the below will be removed when finishAndRemoveTask() API is used.