In android 4.4, swiping app out of recent tasks permanently kills application with its service . Any idea why?

后端 未结 2 812
滥情空心
滥情空心 2020-11-30 04:30

Unlike previous versions, in 4.4, swiping app out of recent tasks permanently kills app along with its service(like force-stop) even though it\'s running background services

2条回答
  •  执念已碎
    2020-11-30 04:49

    From this issue Foreground service killed when receiving broadcast after acitivty swiped away in task list

    Here is the solution

    In the foreground service:

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

    In the manifest:

     
    

    In DummyActivity.java:

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

提交回复
热议问题