GifDecoder problems

boten

Active Member
Licensed User
Longtime User
While testing with the GifDecoder i tried the demo (with the clonesheep). Then I tried to put that VERY SAME code as a 2nd activity module. (the Main activity being simple where a button starts the 2nd activity).

here's what happened:

1. The main starts
2. button pressed
3. Second activity (with GifDecoder) starts
4. button "LOAD" pressed
5. the 1st frame is shown
6. error message: "The Application name (process-name) has stopped unexpectedly. Please try again."

So i tried to isolate the point where it happens so i put 2 Log stmts at btnLoad_Click (1 at the beginning, 1 at the end) and 2 Log stmts at Timer1_Tick (begining & end). The LogCat shows that Timer1 never entered.

Is it a "feature" of GifDecoder that it can't be in an activity module but Main?
 

Kamac

Active Member
Licensed User
Longtime User
The LogCat shows that Timer1 never entered.

Did you initialize it ?


Example from wiki:


B4A Wiki said:
Sub Process_Globals
Dim Timer1 as Timer
End Sub
Sub Activity_Create
Timer1.Initialize("Timer1", 1000) ' 1000 = 1 second
Timer1.Enabled = True
End Sub
Sub Timer1_Tick
'Handle tick events
End Sub


Also, as Agraham said, you will need to post some code to make someone/us find the bug
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
code follows.

BTW, agraham. It's been a loooong time since i saw a Cray
 

Attachments

  • 2apps.zip
    17.1 KB · Views: 259
Last edited:
Upvote 0

boten

Active Member
Licensed User
Longtime User
OK it works, thx. But, can u explain the diff between the two?

I mean, doesn't Process_Globals gets done before Create? If so, Timer1 will be initialized already.
 
Upvote 0

Kamac

Active Member
Licensed User
Longtime User
I mean, doesn't Process_Globals gets done before Create? If so, Timer1 will be initialized already.

No, as process globals description says:

'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

You may only declare variables in it, you cannot do actions inside them.
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
You may only declare variables in it, you cannot do actions inside them

I beg to differ.
The Gifdecoder library, posted by agraham here contained a demo (which runs OK) where
Timer1.Initialize("Timer1",0)
is placed in the Process_Globals.

I don't argue that Klaus's solution works, but I'd like to know why the timer can be initialized in Process_Globals when there is only one Main activity and can not be initialized in the process_globals of a second activity.

Does Process_Globals behaves differently in an activity module (beside the Main)?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You may only declare variables in it, you cannot do actions inside them.
This is not true. It is safe to initialise normal primitive variables and arrays of primitives but to do more you need to know what can and can't be done.

The key to understanding why is that all Sub Process_Globals are run when the application is loaded, not when the Activities containing them are created, and are only run once. This is because they need to be available to all modules. A Timer needs an additional invisible parameter of a BA instance. The BA instance is related to the Activity but as the correct Activity is not available the BA instance the Timer obtains in Process_Globals does not relate to the Activity that contains the Timer Tick event and causes a null pointer exception when the Timer ticks. You can see it in the unfiltered logs.

On the other hand Sub Globals is run on Activity creation so you can initialise the Timer there as a relevant BA instance is passed to it there. However it is better practice to initialise it in Activity_Create ideally inside a test for FirstTime because being a Process_Global the Timer needs initialising only once.
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
....all Sub Process_Globals are run when the application is loaded....

So basically you say that Process_Globals variables can be declared in ANY (sub) activity, am I right?

I also understand from what you say, that altough a Timer can be declared in Process_Globals, it has some "hidden ties" (invisible parameter of its instance) with the activity it "works in", so it must be initialized inside the activity. am I right here?

If so, thks for letting us better undersatand the working flow of B4A.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
at Process_Globals variables can be declared in ANY (sub) activity, am I right?
Yes. Variables declared in Process_Globals are visible across the entire application but if referenced outside the declaring module need prefixing with the module name to be recognised. Main.SomeVar, Myservice.AnotherVar.

a Timer ... must be initialized inside the activity. am I right here?
Yes, in the module where the event Sub is located. For example in your 2AppsTests you could declare the Timer as Timer1 in your main activity Process_Globals but initialise and use it in your act2 activity by referencing it as Main.Timer1.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…