1

My app has Remote, Foreground aidl service which bound to activity. When i clear recent task (by swipe) service destroy. How can i prevent killing of service.

  <service android:enabled="true"
                 android:exported="false"
                 android:stopWithTask="false"
                 android:process=":xplay"
                android:name="com.perm.x.Services.PlayingService"/>

Here is how i bind (in onResume)

 Intent serviceIntent = new Intent(this,PlayingService.class);
        startService(serviceIntent);
        bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);

Here is how i unbind service (in onPause)

unbindService(serviceConnection);
dooplaye
  • 999
  • 13
  • 28

1 Answers1

2

For preventing service from killing i found one hack (actually i did read it somewhere here)

    @Override
    public void onTaskRemoved(Intent rootIntent) {
            Intent intent = new Intent(this, DummyActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
    }

DummyActivity:

public class DummyActivity extends Activity {
    @Override
    public void onCreate(Bundle icicle){
        super.onCreate(icicle);
        finish();
    }
}

And that's it. But there's side effect of this hack - The panel with recents will be immediately hidden after you swipe app of

dooplaye
  • 999
  • 13
  • 28
  • i m starting my activity from onRecieve of my alarm now i want my activity should appear in recent list but there is a condition of i ==2 as soon as i ==2 then this activity should be finished and removed from recent list if i use xml property then it is completely hidden from recent list – Erum Feb 23 '15 at 04:12