It is currently Wed Jun 28, 2017 12:19 pm



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 1, 2  Next
Author Message
 Post subject: Continue running while minimized?
Unread postPosted: Sat Jan 28, 2017 9:22 am 
Offline
User avatar

Joined: Sat Mar 26, 2016 9:23 am
Posts: 94
I'd like to have a program (Timer) continue running while not "on screen".
ie minimized or in background?

Is that possible?


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Sat Jan 28, 2017 10:10 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 659
Location: UK
cavelamb wrote:
I'd like to have a program (Timer) continue running while not "on screen".
ie minimized or in background?

Is that possible?

Yes. I have a simple program that:
(1) Calls another program ("GPS Status") to display progress to a fix
(2) Monitors gps fixes and whether it is in Background()
(3) When fixes are good and not in background, calls another program ("zxing") to show a location barcode and closes.

Step (1) puts my program in background just because another program has been called. But it keeps running, and step (3) is triggered by closing "GPS Status" when you can see that a fix has been obtained. Then my program (briefly!) comes to the foreground and step (3) completes.

You are welcome to a copy, but of course it won't work without installing the other two programs...

If you are curious what the point of the program is, it's for use on aeroplanes to transfer a gps fix from one Android device to another although Bluetooth is not permitted.

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Sat Jan 28, 2017 4:10 pm 
Offline
User avatar

Joined: Sat Mar 26, 2016 9:23 am
Posts: 94
Wow!

I just wanted to keep the bat timer running while doing something else...


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Sun Jan 29, 2017 12:49 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
Hi cavelamb

Do you have any
Code:
gr.render

in your code
If so, try changing them to this
Code:
if ! background() then gr.render


Regards Roy


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Sun Jan 29, 2017 1:46 pm 
Offline
User avatar

Joined: Sat Mar 26, 2016 9:23 am
Posts: 94
roy wrote:
Hi cavelamb

Do you have any
Code:
[color=#000000][/color]
gr.render

in your code
If so, try changing them to this
Code:
if ! background() then gr.render


Regards Roy




Sorry, no help there.
Tried several variations -
IF - then - else
with timer.resume int there as well.
Looks like the service stops when minimized


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Sun Jan 29, 2017 2:23 pm 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 659
Location: UK
cavelamb wrote:
I'd like to have a program (Timer) continue running while not "on screen".
ie minimized or in background?

Is that possible?

There's no point in just having a timer running, so what is the program really doing? No point in rendering while in background either, as Roy was in effect pointing out.

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Sun Jan 29, 2017 2:36 pm 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
The code below runs a little timer.

if you minimized or put it in the background; When you go back to it it will still be running

It may help you

Roy

Code:
Rem Run Timer

di_height = 1150
di_width = 670

gr.open 255, 0, 128, 255
gr.orientation 1 % portrait     
pause 1000
WakeLock 3

gr.screen screenWidth, screenHeight
scale_x = screenWidth / di_width
scale_y = screenHeight / di_height
gr.scale scale_x, scale_y

gosub Functions
gosub Initialise
do
    gosub RunTimer
    call Render()
until 0

onBackKey:
    end
back.resume

!------------------------------------------------
! Do once at first run of app
!------------------------------------------------
Initialise:
    gr.color 255, 255, 255, 255, 0
    gr.set.stroke 4 : gr.text.align 2 : gr.text.size 200
    gr.circle null, di_width / 2, 300, di_width / 3
    gr.set.stroke 1 : gr.color 255, 255, 255, 255, 1
    gr.text.draw txtTimer, di_width / 2, 370, "0:00"
    seconed = time()
    minute  = 0
return

!------------------------------------------------
! Show the timer running
!------------------------------------------------
RunTimer:
    currentSeconed = time() - seconed
    currentSeconed /= 1000
    gr.modify txtTimer, "text", int$(minute) + ":" + int$(currentSeconed)
    if int(currentSeconed) > = 60 then
        minute  ++
        seconed = time()
    endif
   
return

!------------------------------------------------
! All functions below
!------------------------------------------------
Functions:

!------------------------------------------------
! Render if not in background
!------------------------------------------------
    fn.def Render()
        if ! background() then gr.render
    fn.end

return


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Tue Jan 31, 2017 5:01 pm 
Offline
User avatar

Joined: Sat Mar 26, 2016 9:23 am
Posts: 94
That works.

Can you explain why?


Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Wed Feb 01, 2017 1:22 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
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'

The code bellow displays 10 circles modifing there position and colour every second. Text tells you how many displays there as been.

If you run the code and when the display shows 10, put the app in the background. Wait 10 seconds and bring the app back and the dislpay will show 20.

Comment out line 19 and un-comment line 20 save and run the app again and put it in the background and when you bring it back the display will be the same as it was when the app whent in the background.

Hope this help.

There is a bit more info on gr.render in the manual at page 154

Regards Roy
Code:
Rem Keep going in background

di_height = 1150
di_width = 670

gr.open 255, 0, 128, 255
gr.orientation 1 % portrait     
pause 1000
WakeLock 3

gr.screen screenWidth, screenHeight
scale_x = screenWidth / di_width
scale_y = screenHeight / di_height
gr.scale scale_x, scale_y

gosub Initialise
do
    gosub ModifyCircles
    if ! background() then gr.render
    !gr.render
    gosub WaitSeconed
until 0

!------------------------------------------------
! Tap back key to end
!------------------------------------------------
onBackKey:
    end
back.resume

!------------------------------------------------
! Do once at first run of app
!------------------------------------------------
Initialise:
    FALSE = 0 : TRUE = 1
    displayNumber = 0
     ! Setup colours
    dim circleColour[6]
    gr.color 150, 255, 255, 255 : gr.paint.get circleColour[1]
    gr.color 150, 0, 0, 0       : gr.paint.get circleColour[2]
    gr.color 150, 255, 0, 0     : gr.paint.get circleColour[3]
    gr.color 150, 0, 255, 0     : gr.paint.get circleColour[4]
    gr.color 150, 0, 0, 255     : gr.paint.get circleColour[5]
    gr.color 150, 255, 255, 0   : gr.paint.get circleColour[6]
   
    ! Draw 10 circle, each in one of the colours above
    dim myCircle[10]
    for x = 1 to 10
        gr.circle myCircle[x], floor(di_width * rnd()), floor(di_height * rnd()), floor(100 * rnd()) + 10
        c = floor(6 * rnd() + 1)
        gr.modify myCircle[x], "paint", circleColour[c]
    next
   
    ! Draw text
    gr.color 255,255,255 : gr.text.align 2 : gr.text.size 50
    gr.text.draw txtInfo, di_width / 2, di_height / 2, "Display: " + int$(displayNumber)
return

!------------------------------------------------
! Modify the position and the colours of the circles
!------------------------------------------------
ModifyCircles:
    displayNumber ++
    for x = 1 to 10
        c = floor(6 * rnd() + 1)
        gr.modify myCircle[x], "paint", circleColour[c]
        gr.modify myCircle[x], "x", floor(di_width * rnd()), "y", floor(di_height * rnd()), "radius", floor(100 * rnd()) + 10
    next
    gr.modify txtInfo, "text", "Display: " + int$(displayNumber)
return

!------------------------------------------------
! Delay a seconed
!------------------------------------------------
WaitSeconed:
    seconed = time()
    do
        currentSeconed = time() - seconed
        currentSeconed /= 1000
    until currentSeconed > 1
return



Report this post
Top
 Profile  
 
 Post subject: Re: Continue running while minimized?
Unread postPosted: Wed Feb 01, 2017 1:53 am 
Offline
User avatar

Joined: Sat Dec 08, 2012 2:14 am
Posts: 1147
Location: From Blighty
The clue I think, is the WAKELOCK command (see manual). Depends how technical you want to know.

The Android system will allow things to continue to run, for example you could do a tight loop such as this with no WAKELOCK:-

DO
UNTIL 0

That would fry your battery as very CPU intensive, but if you hit the 'Home' button it would just sit there idle and consume no resources in the RAM.

If you need your app to not just sit idle in RAM then that's what WAKELOCK is for.

Messy reasoning now follows:-

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.

?

Mog


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


Who is online

Users browsing this forum: No registered users and 3 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:  
cron
suspicion-preferred