I’m writing an app with an autoplay feature, basically like a story book. I set a media player onCompletionListener for each activity (page) so that when the narration is done, it starts the next activity (page). There’s an option to turn autoplay off (so you can read it at your own pace)…but turning it off results in the activity –the current page– “remembering” the previous onCompletionListener call (as the back button is used to navigate back to the previous activity). The ensuing activities (pages) work fine…as the logic check that starts the onCompletionListener keeps it from being executed.
I’ve also tried moving that logic check to onStart() [instead of onCreate] as the menu where autoplay is toggled takes over the full screen and causes the previous activity (page) to execute onStop(). While this setup keeps the onCompletionListener from being executed again…it still doesn’t “cancel” the previous onCompletionListener. Note: This is only an issue when an activity (page) has been started with the autoplay=on.
I have also briefly tried super.recreate() for that particular activity in an attempt to “restart” everything (hopefully, including the onCompletionListener). However, the result was not pretty (activity blanked out and never reinitialized).
I didn’t include any code as (to me) this is more of a procedural question. 1. can a onCompletionListener be “canceled”. If so, how? 2. If not, (since I’m relatively new to java/android) is the recreate method acceptable/beneficial to “reset” the entire activity (and the onCompletionListener inside it)?
I’m targeting API 11 and above. Any thoughts/constructive criticism would be appreciated.
if you want to cancel a previous setted
onCompletionListener, you can simply set a new one that does nothing.