On Wednesday, June 29, 2011, New Developer <[email protected]> wrote: > I'm struggling to close these two timer tasks > I have @Override public void onCompletion(MediaPlayer arg0) { > try { mMediaPlayer.stop(); > mMediaPlayer = null; if (timer != null) { > timer.cancel(); > timer.purge(); Thread.sleep(500); > } timer = null; } catch (Exception > e) { } } > The sleep just to give it chance to run throughBut I get a > NullPoinerException on the sleep line > Thread [<12> Timer-0] (Suspended (exception NullPointerException)) > Timer$TimerImpl.run() line: 290 > this Timer$TimerImpl (id=830020453552) > currentTime 1309378473189 > pos 0 > task Video2$2 (id=830013266400) > cancelled false > fixedRate false > lock Object (id=830013265024) > period 500 > scheduledTime 1309378473189 > this$0 Video2 (id=830013820608) > when 1309378473690 > > So how does one close the timer once the video has come to and end ? > Thanks in advance
Hey, Glad it worked. You are correct: It plays for 100 milliseconds and pauses in 100. About your NPE, you cannot 'null' the player before cancelling both timer tasks, which means that you need to assign them to variables, rather than use them as anonymous inner classes. Once both timer tasks have been cancelled and the timer has been cancelled too, you can then stop and 'null' the player. Daniel -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

