Q:

How to continue playing music when I killed App

In Android,I use Service and BroadcastReceiver to play music. 
The MediaPlayer can continue playing music when I press Home Button or Back Button. But it can not works when I removed it from Overview Screen.  Even If I set the Service as Foreground Service. 
@0xDEADC0DE points out that the id shouldn't be 0.  I modify it and now it can work well. But it must have a notification. Some Apps such like NetEase Cloud Music,which hasn't any notification and can play even if it be killed,how it works? 
update:
I found that I have closed that app's notification,so it seems still playing music without notification when I kill it....So the problem resolved,thanks 
Here is my code:
MainActivity.java ,
public class MainActivity extends AppCompatActivity implements View. OnClickListener {

private ImageButton mPlayButton;
private ImageButton mPreviousButton;
private ImageButton mNextButton;
private TextView mMusicName;
private boolean mState = false;
private Intent intent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMusicName = (TextView) findViewById(R.id.music_name);
    mPlayButton = (ImageButton) findViewById(R.id.play);
    mNextButton = (ImageButton) findViewById(R.id.next);
    mPreviousButton = (ImageButton) findViewById(R.id.previous);
    mPlayButton.setOnClickListener(this);
    mNextButton.setOnClickListener(this);
    mPreviousButton.setOnClickListener(this);

    intent = new Intent(this, MusicService.class);

    startService(intent);

}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.play:
            if (! mState) {
                //start
                mState = true;
                mPlayButton.setImageResource(R.mipmap.ic_pause_circle_outline_white_48dp);
                Intent intent = new Intent();
                intent.setAction("com.geekband.mo.musicplayer");
                intent.putExtra("action", 0);
                sendBroadcast(intent);

            } else {
                //pause
                mPlayButton.setImageResource(R.mipmap.ic_play_circle_outline_white_48dp);
                mState = false;
                Intent intent = new Intent();
                intent.setAction("com.geekband.mo.musicplayer");
                intent.putExtra("action", 1);
                sendBroadcast(intent);
            }
            break;

        case R.id.next:
            mState = true;
            mPlayButton.setImageResource(R.mipmap.ic_pause_circle_outline_white_48dp);
            Intent intent = new Intent();
            intent.setAction("com.geekband.mo.musicplayer");
            intent.putExtra("action", 2);
            sendBroadcast(intent);
            break;

        case R.id.previous:
            mState = true;
            mPlayButton.setImageResource(R.mipmap.ic_pause_circle_outline_white_48dp);
            Intent intent2 = new Intent();
            intent2.setAction("com.geekband.mo.musicplayer");
            intent2.putExtra("action", 3);
            sendBroadcast(intent2);
            break;

    }
    }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_exit) {
        stopService(intent);
        finish();
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

Service.java ,
public class MusicService extends Service {

private MediaPlayer mPlayer;
private MusicBroadcastReceiver mBroadcastReceiver;

@Override
public void onTaskRemoved(Intent rootIntent) {
    Log.d("MusicService", "onTaskRemoved");
}

private void pause() {
    if (mPlayer ! = null) {
        mPlayer.pause();
    }
}

private void previous() {
    if (mPlayer ! = null) {
        mPlayer.release();
    }
    mPlayer = MediaPlayer.create(MusicService.this, R.raw.loststars);
    mPlayer.start();
}

private void next() {
    if (mPlayer ! = null) {
        mPlayer.release();
    }
    mPlayer = MediaPlayer.create(MusicService.this, R.raw.nanshannan);
    mPlayer.start();
}

private void start() {
    if (mPlayer ! = null) {
        mPlayer.start();
    }
}

@Override
public void onCreate() {
    super.onCreate();

    mBroadcastReceiver = new MusicBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.geekband.mo.musicplayer");
    registerReceiver(mBroadcastReceiver, intentFilter);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    mPlayer = MediaPlayer.create(MusicService.this, R.raw.loststars);

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification noti = new Notification. Builder(MusicService.this)
            .setContentTitle("play")
            .setContentText("playing")
            .setSmallIcon(R.mipmap.ic_launcher)
            .build();
    // manager.notify(0, noti);
    // startForeground(0, noti);
    startForeground(1, noti);
    return super.onStartCommand(intent, flags, startId);
}

@Override
public void onDestroy() {
    if (mPlayer ! = null) {
        mPlayer.release();
    }
    super.onDestroy();
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

public class MusicBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        int action = intent.getIntExtra("action",0);
        switch (action) {
            case 0:
                start();
                break;

            case 1:
                pause();
                break;

            case 2:
                next();
                break;

            case 3:
                previous();
                break;

        }
    }
}
}

A:

Your service gets killed just like all other resources of your app if you remove it from the task switcher or when you kill the app.  By killing/removing it from the task switcher, the process is stopped.  Your service lives in that same process and is therefore also stopped.  This is simply how Android (and other operating systems) works. 
EDIT
This is indeed possible, but according to the documentation, you should not use startForeground with an ID of 0:

Caution: The integer ID you give to startForeground() must not be 0. 

http://developer.android.com/guide/components/services.html#Foreground

