sqlite in background

4 replies [Last post]
gryzlaw
User offline. Last seen 2 years 33 weeks ago. Offline
Joined: 29 Jun 2011

I'd like to do some relatively heavy data transformation (mostly inserts and updates) but I'd also would like to run an animation in the foreground (to indicate processing).

Unfortunately I can't find a way to create an asynchronous method so that I can run both the sqlite initialization method and the loading animation (using sprite sheets).

Are there any lua/corona features I'm missing or any work around which I haven't thought of?

Thanks

Replies

JayantV
User offline. Last seen 2 weeks 1 day ago. Offline
Joined: 31 Oct 2009

@gryzlaw,

depends on what kind of animation, you can have a sprite animation that keeps looping forever and you can stop it when the SQL returns with some data.

the way would be to load the spritesheet and set the animation to loop forever, then run the SQL command and when it completes, then stop the animation.

cheers,

?:)

gryzlaw
User offline. Last seen 2 years 33 weeks ago. Offline
Joined: 29 Jun 2011

@jayantv,

That's what I would have expected, but it didn't work as I thought.

With this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
        local spritext = require "spritext" -- tried also normal sprite animation
        
        local loading = spritext.newAnim("loading.png", 60, 60, 1, 8); 
        loading.x = display.contentWidth / 2
        loading.y = display.contentHeight / 2 - 30
        loading:play()
        localGroup:insert(loading)
        
        local function initialise()
                db.doInit() -- the databse inputs are here
                director:changeScene( "intro")
        end
        timer.performWithDelay(500, initialise, 1)      

The result is a loading animation for 500ms than the application and the animation (seemingly) block, until the database inserts finish and the scene changes.

I've actually also tried to update the sprite (using loading:nextFrame()) after every insert, but that too did not update.

Any other ideas?

gryzlaw
User offline. Last seen 2 years 33 weeks ago. Offline
Joined: 29 Jun 2011

Really, no ideas anyone?

gtatarkin
User offline. Last seen 15 hours 26 min ago. Offline
Joined: 16 Dec 2010

use coroutine Luck :)

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.