How to run a B4A app in the background ?

StepWalk

Member
Licensed User
Longtime User
I am new here. So first let me say that B4A is a great advance for my effort in building Android apps. I startet first with Eclipse trying to get into that "very special" Java world. Well.. after several days fiddeling around I even manged to customize the "Hello World" application. Not that encouraging... at least for me. Then I came across to that B4A and it was like a flash. It didn't take even one hour to feel familiar with it. That's the way... great stuff... Absolutely worth the money.

Now - what I want to build is some app that stays awake in the background listening to incoming SMS, processing their content, and calling (by intent) GoogleMaps accordingly.

Until now I couldn't figure out how put a running (not pausing or sleeping) B4A app in the background and how to connect some activity to the phone event that I would describe as "New SMS received"

As a workearound I used "SmsMessages.GetAllSince(...)" in a polling loop - but that's a quite uncool approach - and it falls asleep once you click that app in the background.

Any advice - even the smallest one - would be greatly appreciated!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Android handles applications differently than Windows.
Once your activity is not in the foreground, it is paused and cannot execute any code.
See this tutorial: http://www.b4x.com/forum/basic4andr...87-android-process-activities-life-cycle.html

Services are used instead of activities to handle tasks while the application is in the background. Basic4android doesn't support services yet. The Services concept is pretty complicated. Much more than creating an activity.
I believe that support for services will be available soon.
 
Upvote 0

StepWalk

Member
Licensed User
Longtime User
Thanks for your quick reply, Erel. Now I got some clue about the different behavior of "services" and "activities" and your link shed a little more light on the back stage scene of that Android system. Ok, so let's wait a bit for the coming B4A support for "services" . Chances are it comes earlier than I would manage to accomplish that task in Java :)

Once more, B4A is a cool tool. I love it.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Does anyone know how soon this will be available, as I am looking at purchasing the Standard edition, but would only have 2 months free updates.

Will it DEFINITELY be within the next 2 months, or do I need to wait before purchasing?
 
Upvote 0

Frogger

Member
Licensed User
Longtime User
Does anyone know how soon this will be available, as I am looking at purchasing the Standard edition, but would only have 2 months free updates.

Will it DEFINITELY be within the next 2 months, or do I need to wait before purchasing?

I really do hope it's soon because I can't afford to buy this again :(
 
Upvote 0

Frogger

Member
Licensed User
Longtime User
I cannot afford to buy it twice, and need this functionality. So I guess I wait...............:sign0148:

I wish I hadn't purchased Basic4Android now :( I was worried about it only having 2 months of updates - looks like I was right to worry. :sign0148:

Why does Basic4ppc (which I also purchased) get 1 year of updates but Basic4Android only get 2 months!?
 
Last edited:
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
Its money well spent in my book. B4A is very feature rich and stable. Erel is also responsive and helpful to forum questions. One happy customer here
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
App running in background

Hi all, is this feature included in the 1.7 version or not, i want to make an app also that will run in the background, any clues?
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
App running in background

Great so that means that now we can run apps in the background, if so is there any examples on how to do this?:sign0060:
 
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
Great so that means that now we can run apps in the background

Yes exactly.
if so is there any examples on how to do this?:sign0060:

You should start by reading Klaus' Beginner's guide.
I think it should include Services (form where it works in the background) somewhere. Otherwise for Services, you can start reading here.

All other documentation is found here or the Basic4Android Documentation Wiki.

To make a service: Click Project - Add new module - Service Module

You should start a service from an activity (usually) to work in the background with:
B4X:
startservice(servicename)

and stop a service with:
B4X:
stopservice(servicename)


Sincerely,
Tomas
 
Last edited:
Upvote 0
Top