이것은 안드로이드 6,7,8,9에서 나를 위해 일했습니다.
다음과 같이 하나의 서비스를 만드십시오.
public class OnClearFromRecentService extends Service {
@Override public IBinder onBind(Intent intent) {
return null; }
@Override public int onStartCommand(Intent intent, int flags, int
startId) {
Log.d("ClearFromRecentService", "Service Started");
return START_NOT_STICKY; }
@Override public void onDestroy() {
super.onDestroy();
Log.d("ClearFromRecentService", "Service Destroyed"); }
@Override public void onTaskRemoved(Intent rootIntent) {
Log.e("ClearFromRecentService", "END");
//Code here
stopSelf(); } }
2)이 서비스 등록 manifest.xml:
<service android:name="com.example.OnClearFromRecentService"
android:stopWithTask="false" />
3) 그런 다음 스플래시 활동에서이 서비스를 시작하십시오.
startService(new Intent(getBaseContext(),
OnClearFromRecentService.class));