In the following example if someone if someone presses the home button while the task is running, then the task is cancelled. In this particular cancelling it should interrupt if running.
public class MainActivity extends AppCompatActivity {
private static AtomicBoolean inWork;
pri...