anOparator Active Member Licensed User Longtime User Dec 23, 2017 #1 I click Menu icon on Main activity: - Button1 opens Activity2(Webview1), the Back button takes me back to Main activity. - Button 2 makes Searchview1 visible in Main activity. The following Sub enables the Back button to do Searchview1. Visible=False and Main stays active. Code: Copy Sub Activity_KeyPress (key As Int) As Boolean If key = KeyCodes.KEYCODE_BACK Then If Searchview1. Visible=True Then Searchview1.Visible=False Panel1.Visible=True Return True Else Return False End If End If End Sub Pressing Back again closes everything as expected. Would someone tell me what is causing a 'Not all code paths return a value'. I've read https://www.b4x.com/android/forum/t...ctivity-and-get-a-return-value.84804/#content and still need more to read. Thanks
I click Menu icon on Main activity: - Button1 opens Activity2(Webview1), the Back button takes me back to Main activity. - Button 2 makes Searchview1 visible in Main activity. The following Sub enables the Back button to do Searchview1. Visible=False and Main stays active. Code: Copy Sub Activity_KeyPress (key As Int) As Boolean If key = KeyCodes.KEYCODE_BACK Then If Searchview1. Visible=True Then Searchview1.Visible=False Panel1.Visible=True Return True Else Return False End If End If End Sub Pressing Back again closes everything as expected. Would someone tell me what is causing a 'Not all code paths return a value'. I've read https://www.b4x.com/android/forum/t...ctivity-and-get-a-return-value.84804/#content and still need more to read. Thanks
ilan Expert Licensed User Longtime User Dec 23, 2017 #2 anOparator said: Would someone tell me what is causing a 'Not all code paths return a value'. Click to expand... the _KeyPress Sub is not only for the Back Button. Its also for the Volume Button and for the Menu Button,... so when you filter it and say if pressed button is the Back Button then do this but what will happen if its not the Back button?? so adding on the bottom "Return False" will clear that warning. Code: Copy Sub Activity_KeyPress (key As Int) As Boolean If key = KeyCodes.KEYCODE_BACK Then If Searchview1. Visible=True Then Searchview1.Visible=False Panel1.Visible=True Return True Else Return False End If End If Return False '<---------- End Sub Note that the KeyPressed sub is expecting a returned value (in our case a Boolean) so that value must be returned in any possible case otherwise its a sub that returns a value without really doing it in any scenario. Upvote 0
anOparator said: Would someone tell me what is causing a 'Not all code paths return a value'. Click to expand... the _KeyPress Sub is not only for the Back Button. Its also for the Volume Button and for the Menu Button,... so when you filter it and say if pressed button is the Back Button then do this but what will happen if its not the Back button?? so adding on the bottom "Return False" will clear that warning. Code: Copy Sub Activity_KeyPress (key As Int) As Boolean If key = KeyCodes.KEYCODE_BACK Then If Searchview1. Visible=True Then Searchview1.Visible=False Panel1.Visible=True Return True Else Return False End If End If Return False '<---------- End Sub Note that the KeyPressed sub is expecting a returned value (in our case a Boolean) so that value must be returned in any possible case otherwise its a sub that returns a value without really doing it in any scenario.
anOparator Active Member Licensed User Longtime User Dec 27, 2017 #3 Thanks, makes sense. Reminds me of Timer1.Enabled = False Upvote 0