It is currently Sat Apr 29, 2017 10:30 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Continue running while minimized?
Unread postPosted: Wed Feb 01, 2017 2:24 am 
Online

Joined: Tue Dec 04, 2012 10:50 am
Posts: 644
Location: UK
Mog wrote:
I don't however understand how BACKGROUND () works, it must not idle the CPU in order for the program being able to be 'brought back to life'? Or does control then end up with OS? Thinking additionally, it must pass something, a flag if you like to the Android OS to say it's there and the .apk needs to be brought back.

Messy reasoning, as you say! ;-)

BACKGROUND() is merely an instantaneous test of current condition. It causes no change in condition of itself, so no flag-passing. Hence its uses are either to suppress a render if the program is not visible so the effort would be wasted (though it would be better to suppress the update preparation rather than the final step of rendering). Or to move on to another stage of processing, like my geo-QR-code example. In either case it is likely to be in a polling loop.

HTH, Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Fri Feb 03, 2017 5:51 pm 
Online
User avatar

Joined: Sat Mar 26, 2016 9:23 am
Posts: 73
roy wrote:
cavelamb wrote:
That works.

Can you explain why?

Hi cavelamb

if you use gr.render in you app and you put you app in the background gr.render will pause you app.

If you want you app to keep running in the background then use 'if ! background() then gr.render'


If I didn't ask dumb questions I probably wouldn't learn much.
Thanks, Roy.
That helped.


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Wed Mar 29, 2017 7:24 pm 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2795
Location: Colorado, U.S.
Nothing like replying two months later, eh? I don't know if anyone will see this...

Anyway, you don't need WAKELOCK or any other fancy stuff just to run in the background. Run this:
Code:
for i=1to60;pause 1000;next
While it's running, press the HOME key. Some seconds later, start BASIC! again; doesn't matter if you go from the launcher or from the "recents" list (square button).

The HOME key stops the current activity and puts it on the Android backstack. No UI action is possible. In BASIC!, the current activity is either the Console, the Graphics screen, or the HTML WebView. All of those can sit on top of the BASIC! interpreter.

The BASIC! interpreter is ALWAYS in the background, in the sense that it is not running in the UI thread. It's not part of an Android "activity", it's running in its own thread. So hitting the HOME key (or executing the HOME command) does not stop your program. It keeps right on running.

Except, as Roy said, if you ask it to render on the graphics screen, and the graphics screen is stopped, the program waits for the graphics screen to start up again. That's why you need the background() check.

Of course, if the Android device goes into a idle state or sleep state, it stops pretty much everything. That would pause the interpreter along with everything else. You use WAKELOCK to keep running even if the rest of the device is asleep.

Another possible background problem is that the activity that owns the UI (shows on the screen) has higher priority than background tasks. If you have a BASIC! screen showing, it keeps the interpreter at high priority, too. If you put the BASIC! activity in the background, the interpreter is still running, but now whatever is on the screen has higher priority than BASIC!. If the system needs memory for the app on the screen, it kills off background apps. So while you're running BASIC! in the background, it is vulnerable to being killed by the Android system.

I hope that's clearer. You can do a lot with BASIC! without knowing much about Android, but for some things, like changing screens or running the background, you have to understand the way Android works.

- Marc


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Wed Apr 12, 2017 2:30 pm 
Online
User avatar

Joined: Sat Mar 26, 2016 9:23 am
Posts: 73
A month later reply...

Thanks Marc.
That almost makes reasonable sense.
:)

But really, yes, it really does make more sense now.


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred