boten Active Member Licensed User Longtime User Aug 1, 2011 #1 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?
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?
K Kamac Active Member Licensed User Longtime User Aug 1, 2011 #3 The LogCat shows that Timer1 never entered. Click to expand... 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 Click to expand... Also, as Agraham said, you will need to post some code to make someone/us find the bug Upvote 0
The LogCat shows that Timer1 never entered. Click to expand... 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 Click to expand... Also, as Agraham said, you will need to post some code to make someone/us find the bug
boten Active Member Licensed User Longtime User Aug 1, 2011 #4 code follows. BTW, agraham. It's been a loooong time since i saw a Cray Attachments 2apps.zip 2apps.zip 17.1 KB · Views: 417 Last edited: Aug 1, 2011 Upvote 0
klaus Expert Licensed User Longtime User Aug 1, 2011 #5 You must move the line Timer1.Initialize("Timer1",0) from Process_Globals to Activity_Create and it works fine. Best regards. Upvote 0
You must move the line Timer1.Initialize("Timer1",0) from Process_Globals to Activity_Create and it works fine. Best regards.
boten Active Member Licensed User Longtime User Aug 1, 2011 #6 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
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.
K Kamac Active Member Licensed User Longtime User Aug 1, 2011 #7 I mean, doesn't Process_Globals gets done before Create? If so, Timer1 will be initialized already. Click to expand... 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. Click to expand... You may only declare variables in it, you cannot do actions inside them. Upvote 0
I mean, doesn't Process_Globals gets done before Create? If so, Timer1 will be initialized already. Click to expand... 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. Click to expand... You may only declare variables in it, you cannot do actions inside them.
boten Active Member Licensed User Longtime User Aug 1, 2011 #8 You may only declare variables in it, you cannot do actions inside them Click to expand... 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
You may only declare variables in it, you cannot do actions inside them Click to expand... 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)?
agraham Expert Licensed User Longtime User Aug 1, 2011 #9 Kamac said: You may only declare variables in it, you cannot do actions inside them. Click to expand... 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
Kamac said: You may only declare variables in it, you cannot do actions inside them. Click to expand... 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.
K Kamac Active Member Licensed User Longtime User Aug 1, 2011 #10 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. Click to expand... Thanks for letting me know Upvote 0
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. Click to expand... Thanks for letting me know
boten Active Member Licensed User Longtime User Aug 2, 2011 #11 agraham said: ....all Sub Process_Globals are run when the application is loaded.... Click to expand... 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 said: ....all Sub Process_Globals are run when the application is loaded.... Click to expand... 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.
agraham Expert Licensed User Longtime User Aug 2, 2011 #12 boten said: at Process_Globals variables can be declared in ANY (sub) activity, am I right? Click to expand... 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? Click to expand... 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
boten said: at Process_Globals variables can be declared in ANY (sub) activity, am I right? Click to expand... 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? Click to expand... 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.