Android Event Listener v1.0.0 - find out when your app is put in the background!

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by Opaquer » Thu Sep 10, 2020 3:53 am

Hey everyone (also Jacque, who I'm sure is the first person here reading this!)

I'm not sure if this is the right place to put this, so if it's not feel free to move it to a different forum - I just thought it'd be a good place for beginners to find if ever someone's looking for this down the line :)

I would like to introduce my first LC Extension - the Android Event Listener! It came about from the need for us to find out when our app was placed into the background, and to run a handler accordingly, as well as running a handler when the app comes out of the background!

It's now on the extension store so you can download it and give it a shot! Naturally, for something this good, all I'm asking for is $1,000,000,000 per download, which I think is a pretty reasonable price for it :)

All you have to do is start the event handler in your card/stack open script, and close it on the close script. When the stack is paused, it should run the "StackPaused" handler, and when the stack is resumed, it should run the "StackResumed" handler, so as long as these are in the right places, you can make it do whatever you need!

I'm still super new to this, so if you don't have one of the paused/resume handlers in there, it'll throw an error in the IDE, but I'm not sure how to fix it, so until then, maybe just have both even if one's not needed, and have the code on it to nothing :)

Hopefully you can all make use of this, and if you have any questions/comments/bugs, please don't hesitate to let me know!

Good luck, and happy coding (and happy finding out when your app is suspended/resumed!)

Opaquer

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 926
Joined: Fri Aug 15, 2008 7:15 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by bangkok » Thu Sep 10, 2020 10:03 am

Hey mister Opaquer !

This is totally.... great !

No seriously.

I'm going to try it.

Do you have any plan for other Android extensions ?

Thanks again.

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by Opaquer » Thu Sep 10, 2020 10:07 am

Thanks for the kind words Bangkok!

Please try it out and let me know how it is - hopefully it works properly and everything :)

As for future Android extensions, I don't have any plans at the moment, since this is all I need for my current app, but who knows about what's going to happen in the future, so we'll see!

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 926
Joined: Fri Aug 15, 2008 7:15 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by bangkok » Thu Sep 10, 2020 10:26 am

Well after a few tests (Android 7)... it works perfectly.

One thing I didn't realize. If for instance I put an
answer "paused"
and
answer "resumed"
into the handlers.... the "paused" is fired, but of course not the "resumed" (because the screen displays the "paused").

Anyway, thanks again ! I'm sure this little extension will be useful. :D

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by Opaquer » Thu Sep 10, 2020 10:55 am

Actually that's a very good point - I hadn't tried that before! The resumed handler gets fired as soon as you get back into the app, so if there's something already open like an answer window, it won't be able to send another one unfortunately! If you absolutely need to have both answer things, there'd be ways around it, I'm sure!

PaulDaMacMan
Posts: 324
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by PaulDaMacMan » Thu Sep 10, 2020 5:28 pm

Opaquer wrote:
Thu Sep 10, 2020 3:53 am

It's now on the extension store so you can download it and give it a shot! Naturally, for something this good, all I'm asking for is $1,000,000,000 per download, which I think is a pretty reasonable price for it :)
Hey man, great to see you got it working! It would be helpful to others trying to get started if you would post the .lcb source code used to build your extention. Maybe you could make a GitHub repo for it, or just attach it in in a forum post. I'd even take a look to see if I can help work out the kinks (I still think the engine shouldn't throw an error if the posted "stackPaused" & s"stackResume" messages aren't handled).

I hadn't realized that the extension store is accepting uploads from the general again/now... I think the last time I tried to upload one of my libs/widgets was a few years ago. It seems the extension store integration of the LC IDE is still very much broken because that's where I first looked for your extension.
My LCB Repos: https://github.com/PaulMcClernan/

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by Opaquer » Fri Sep 11, 2020 1:17 am

I couldn't have got it working without you - thanks for all your help :)!

Also I can totally get the .lcb file loaded and ready to go - question is where would be the best place to upload it on the forums? Just here you think?

Also, I've noticed the extension store in the IDE is a bit funny too - maybe it takes time before it shows up or something? I'm not sure?

kdjanz
Posts: 232
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by kdjanz » Fri Sep 11, 2020 5:08 am

May I suggest that you put it up on GitHub and put a link up here?
Most of the folks that are interested in source code and under the hood stuff are already over on Github and used to looking there...

Also, if you make any changes or updates, Github can notify the interested people if they have signed up for that.

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by Opaquer » Fri Sep 11, 2020 7:53 am

Sounds good - I've never used Github before, so I'll have to look to see how it works and get it set up :). I'll look into it and see what I can find!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by Opaquer » Fri Sep 11, 2020 8:17 am

Hey guys, just a quick update: I threw something together in Github - not sure if I've done it right or if I've missed anything, but here's the link to it: Android Event Listener on Github

kdjanz
Posts: 232
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by kdjanz » Fri Sep 11, 2020 3:37 pm

Looks good to me on Git.

Amazing how simple the code is once you’ve got it sorted! But the process of getting it there...

Hopefully this will help others go further to smooth some of the sharp edges still out there.

Thanks again!

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by Opaquer » Fri Sep 11, 2020 3:49 pm

No worries!

And absolutely, while the code isn't long itself, it took me about 2-3 real days from start to finish, including posting for help a bunch of times before finally sorting it out :-P. Like you said, hopefully it'll be a great point to lead from in the future if anyone else has any questions or anything!

PaulDaMacMan
Posts: 324
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by PaulDaMacMan » Fri Sep 11, 2020 11:21 pm

Opaquer wrote:
Fri Sep 11, 2020 7:53 am
Sounds good - I've never used Github before, so I'll have to look to see how it works and get it set up :). I'll look into it and see what I can find!
I started using GitHub just so I could contribute to fixing up the docs in the LC IDE, now I have a bunch of my own repos there. I just use the web interface for doing Git stuff, instead of command line Git that a lot of Devs use. It's not that hard to use via the web (once you figure out the basics ). GitHub is good because other users can improve on your code and "push" those improvements for you to accept (or not).

Edit:
Just saw that you have a GitHub repo
Hmm...I don't see anything wrong in your "post" lines in your LCB. Maybe it's a bug / feature of the Android version of the engine that is making it throw an error if the StackPaused/StackResumed messages aren't handled? I would think it would react the same way as the desktop versions of the engine and just ignore any messages that aren't handled by a script, like at the beginning of this demo of my (brand spankin' new) Piano Widget, where the noteOn/noteOff messages that the Widget posts aren't handled by an LCS script until later on in the video:
https://www.youtube.com/watch?v=xg7rBg8 ... =youtu.be
My LCB Repos: https://github.com/PaulMcClernan/

Opaquer
Posts: 247
Joined: Wed Aug 14, 2013 8:24 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by Opaquer » Sat Sep 12, 2020 12:17 am

It could very well be that if they're not handled, nothing happens, but in my test extension I put a test handler in that I didn't have anything for and the IDE threw an error, so I didn't want to risk it with the listener :-P

okk
Posts: 136
Joined: Wed Feb 04, 2015 11:37 am

Re: Android Event Listener v1.0.0 - find out when your app is put in the background!

Post by okk » Mon Sep 21, 2020 2:49 pm

Hi and thanks for this extension. This seems very useful, I will give it a spin. Also great that you dared to jump into LCB water. I would have a lot of ideas for extensions, but I am still busy learning livecode, so LCB is out of my reach for now. Anyway, thanks again and congratulations! Best. Oliver

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”