问题描述:

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.

网友答案:

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();
相关阅读:
Top