-3

I have an app with a background process running with a notification image on top of it. I want to close the app by clicking a button inside of the App. Currently I have to force close it from the settings. What do I have to change in the code bellow to achieve this?

1:

 Intent homeIntent = new Intent(Intent.ACTION_MAIN);
    homeIntent.addCategory( Intent.CATEGORY_HOME );
    homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(homeIntent);

2:finish();

3:System.exit(0);

The three codes above closes the app but the background process with the notication image is still running.

Hans1984
  • 796
  • 11
  • 24
mydeve
  • 553
  • 1
  • 14
  • 39

1 Answers1

-1

For remove top notification

notification.flags |= Notification.FLAG_AUTO_CANCEL;
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

For stop service :

stopService(new Intent(this,ServiceName.class));

In service class :

stopSelf();
Anand Savjani
  • 2,484
  • 3
  • 26
  • 39