I’m having a specific problem that I’d love some insight on. Here is my code
Intent i = new Intent();
i.setDataAndType(media, mediaType);
startActivity(i);
This starts an audio activity for me and it even puts a notification item in the notification bar saying that it is an ongoing task. However, if I hit the Home button or Back button the ongoing task is immediately killed for me. I was confused by this behavior.
I found a way to keep the task going by the following: when the audio activity starts I drag down the notification bar and click the notification item ( which really just shows me the same activity again ) and when I do this it behaves accordingly. When I click the Home button it continues. When I hit the back button, it continues. For some reason when I click the notification item the “correct” Intent is fired.
What I’d like is for this behavior to start when I first launch the audio, because no one that uses my app is going to pull down the notification bar and click the notification item to get this to work properly.
Use a
Service. Specifically, you will want to callstartForegroundService()in the service’s creation/start callback.