For Activity Lifecycle

Hi,
OnPause, OnStop, OnResume, everything works like a charm. I am saving all my variables to TyniDB each time when I Pause and/or Stop. Loading them back when I start the app.

There one thing I cannot do: disconnect from BLE when I hit the home/pause button. I receive an error. I do not think it is possible but I would like to disconnect from BLE when I hit this button from anywhere in the app.

regards
Henk

You can try this.

'vknow360' Thanks for answering,
HomeWatcher.aix does not work for me.
tried the: when homebutton clicked block

Henk

Maybe it needs some time to disconnect. So try to use a timer.

And post a screenshot of the error message.

SHUBHAMR69,
Tried several times with the StartWatching block at different places in the ScreenInit block. But no succes yet. BLE stays connected.

Henk

Anke
I did not use a timer yet. But the appears when I implement the BLE disconnect in the 'When.Onstop' block. In the 'When.Onpause' block no error but also no BLE disconnect.

The error says (at .Onstop):
Error 3300 Error 9500 Disconnect cannot be called before you are connected. There's no BluetoothLE device currently connected.

But that's strange because my connection is still valid (BLE connection-led is still ON at the receive side) and when I resume the app it is still operating over BluetoothLE as before.

It is a pity because I like the way the extension works. (automatic, you do not have to care about it)

Henk

I think, you can use BackgroundTask extension by @Kumaraswamy to disconnect the BLE on Home Pressed.

It works but only when phone has 3-button navigation.

1 Like

My phone has a 3 button navigation. Only the pause/halt (middle one) is a physical one. The two adjacent ones are touch sensitive on the frame.

Anke: update
Both implementations (.OnStop & .OnPause) are giving 'BLE cannot disconnect' errors. The .OnPause error was underneath the Paused screen.

Henk

Then,maybe try using StartWatching block on button click as some extensions don't work correctly on Screen Initialize.

1 Like

As I said, use a timer and post a screenshot of the error message.
And please show your blocks.

Does the disconnect method work if you use / execute it before you press the Home button?
What happens if you put this block in the Screen.BackPressed event? Do you get then the same error?

MY FAULT ! (Solved)
Activity Lifecycle works perfectly. For switching between BLE auto connection and manual connection I am using a flag. Flag was set wrong and AL connected immediately after disconnecting so it looked like BLE stayed connected.

I am using the BLE disconnect block in the .OnPause block only because the .OnStop is always advanced by the .OnPause (Works perfect now)

I am sorry to cause you these solution thoughts but it helped me to find the fault in my app

thanks
Henk

What do we learn from this? Always the same:
ALWAYS post your blocks!

4 Likes