Search code examples
androidandroid-intentandroid-activityexoplayer

Keep activity while the app is not on top of screen


I got a problem with multitasking, its probably a stupid question but after looking for hours an answer, i dont know how to do it everybody seems got that by default.

So my problem is I've two activities A (main) and B (conataing exoplayer), A--->B but when im on B and i press lock button or switch app: onPause is been called (normal) and onStop too, i reopen the app, and I'm back to A, the instance of B seem destroyed but the player still playing the audio.

What i would like to do is Keep B how it was or pause the audio/video on hold B, most important thing is to keep b on top and not go back to main (A).

Thanks for your help.


Solution

  • Try to start your activity B with:

    Intent intent = new Intent(this, ActivityB.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    

    This will start ActivityB as a new task and destroy ActivityA, so returning to it should not be possible. If you currently have some flags added to either ActivityA or B, they could also be interferencing with returning to desired activity after pressing home button.