Problem with power button "Pause and Resume" on Kindle Fire

staticmike

Member
Licensed User
Longtime User
Hi
I am a Noob and slowly getting to grips with writing my 1st app for the Amazon Kindle Fire. I have hit a brick wall with a problem and have browsed the forums for a understanding of the Pause and resume functions and have just about figured it out apart from the problem outlined below.

I have a mediaplayer and timer both of which are declared in the
Sub Process_Globals as described in various posts.

My activity_pause routine pauses the mediaplayer and stops the timer and the activity_resume starts the mediaplayer and the timer.

This all works hunky dory when I press the home button or change the soft volume button as described in the logs below -

"Normal Operation - Home Button Pressed"

** Activity (jukescreen) Pause, UserClosed = false **

"App Run Again"

** Activity (jukescreen) Resume **

"Normal Operation soft volume pressed"

** Activity (jukescreen) Pause, UserClosed = false **

"App got focus again"

** Activity (jukescreen) Resume **


However when I press the physical power button all hell breaks lose as shown below -

"Power Pressed off" -

** Activity (jukescreen) Pause, UserClosed = false **
** Activity (jukescreen) Create, isFirst = false **
WakeLock already held.
** Activity (jukescreen) Resume **


"Power Pressed again to switch on"

** Activity (jukescreen) Resume **
** Activity (jukescreen) Resume **
** Activity (jukescreen) Pause, UserClosed = false **
** Activity (jukescreen) Create, isFirst = false **
WakeLock already held.
** Activity (jukescreen) Resume **



What I would expect is when you press the power off button the app should pause just like when the home button is pressed and resume just like before but because resume is kicking in all by itself the music starts to play again.
Please help me as I dont have much hair left to pull out and it is driving me round the twist !!

Many thanks
Mike
 

staticmike

Member
Licensed User
Longtime User
Not sure what wakelock is ? Is this because I have called Keepalive(false) in the activity_create sub.
I have added this to stop the screen turning off but thought I read on forums that power button will still turn device off ?

Thanks
Mike

B4X:
Sub Activity_Create(FirstTime As Boolean)

      activity.LoadLayout("mainscreen") 'load screen
      ph.KeepAlive(False)

      '1st time run
      If firsttime Then
            
         'Set song position at 1
         songposition=1      
         'set prev and next label text depending how many songs there are
         If main.totalsongs <100 Then
            lblprev.Visible=False
            lblnext.Visible=False      
         End If   
         'Initialise mediaplayer
         mediaplayer1.Initialize()
   
         'set random timer 
         Tmrrandom.Initialize("Tmrrandom", 1500) ' 1000 = 1 second
         tmrrandom.Enabled = True

      End If
      
      displaysongs
      lbltotalsongs.text="Total Songs - "&main.totalsongs
      
   
   
End Sub

Sub Activity_Resume

   If pausecontrol=True Then 'restart playing
      imgpause_click
   End If

   'start timers
      tmrrandom.enabled=True
   
   
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)   
   
   ' If userclosed ie back then exit else pause playback
   If userclosed Then
   ' Back pressed so exit
      ExitApplication      
   Else
      ' Pause music if not already paused and show pause icon
      If pausecontrol=False Then
         imgpause_click
      End If
      
      
      'stop timers
      tmrrandom.enabled=False
      
   End If   
   
   End Sub
 
Last edited:
Upvote 0

staticmike

Member
Licensed User
Longtime User
Had a bit of a break through !! Tested on emulator and everything works fine when I press fn7 - Power off. Thinking it maybe a Kindle Fire issue.
I have managed to solve it by working around it. I created a control variable in global then added to the value when the false resumes were activated


** Activity (jukescreen) Create, isFirst = false ** Add 1
WakeLock already held.
** Activity (jukescreen) Resume ** add 1

Only when true resume called ie power on
** Activity (jukescreen) Resume ** add 1


Now the value is 3 so start media player and timers and reset control variable to 0.

Bit of a "Gaffer Tape" fix but it has fixed the problem !!
 
Upvote 0
Top