Android Tutorial How to make a simple splash scree (that you can understand)

This is tutorial of how to make a splash screen in B4A. There are 3 sections. Just copy and past the code. In the designer save the layout as "LayoutMain.bal" and make a "Panel1" in that layout. "Panel1" will be the splash screen. You can change the length of the the timer from 3000 millisecs (3 seconds) to a different number if you want. Hope this helps.


===========================================
1) dim 'Timer1' in globals so subroutine can see it (remember case sensitive)


Sub Globals
Dim Timer1 As Timer


===========================================

2) Create a layout in the designer "LayoutMain.bal". In there make "Panel1" with the splash screen. Make sure it's set to visible in the designer. You might want to bring Panel1 to front (in the designer, click on the panel and then at top bring to front). "("Timer1", 3000)" sets the screen to 3 seconds.


Sub Activity_Create(FirstTime As Boolean)
'--------------------------------------------------
'Display layout
Activity.LoadLayout("LayoutMain.bal")
'--------------------------------------------------
'splash screen - title screen - 2 secs
Panel1.Visible=True
Timer1.Initialize("Timer1", 3000)
Timer1.Enabled=True


===========================================
3) Create a subroutine with this. This turns off the panel AND turns off the timer.


Sub Timer1_tick

Panel1.Visible=False
Timer1.Enabled = False
End Sub


===========================================
4) Remember the B in BASIC stands for beginners!!!!!!
 

Hero post

Member
Licensed User
Longtime User
Splash screen 'newbee' problem?

Hi,
I am relatively new to B4A, and I was trying several of the examples.
Most of them work like a charm.
Whne I tried te splash screen example, my virtual machine keeps 'force closing' on me.
It shows the panel (without my .png picture) very briefly and then *poof*. Error.
LayoutMain is a layout i created using the Designer. I just holds a panel called Panel1.
Here's the code i've been using (prepare to see things you've seen before)
'Activity module

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

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Panel1 As Panel
Dim Timer1 As Timer
End Sub

Sub Activity_Create(FirstTime As Boolean)
'--------------------------------------------------
'Display layout
Activity.LoadLayout("LayoutMain.bal")
'--------------------------------------------------
'splash screen - title screen - 2 secs
Panel1.Visible=True
Timer1.Initialize("Timer1", 3000)
Timer1.Enabled=True
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub



Sub Timer1_tick



Panel1.Visible=False

Timer1.Enabled = False

End Sub
 

pluton

Active Member
Licensed User
Longtime User
What kind of error writes when you start the app in debug mode?
or
As Erel says check unfiltered logs then write here
 

pluton

Active Member
Licensed User
Longtime User
For @Hero post

Here in the atachment you have a example with one panel with .png image.
Image is 256x256 pixels

Just download and start to test it.
Here is screenshot
splash.png


Attachment is bellow :D
 

Attachments

  • Splash_Example.zip
    94.9 KB · Views: 2,434

Hero post

Member
Licensed User
Longtime User
Thanks

Thanks a lot,
I hope to find time tonight to test all of the replies I received (starting of course with the example.)
See if I can work out where I went wrong.
 

Hero post

Member
Licensed User
Longtime User
Thanks Pluton,
It works like a charm.
Now I still have to find where I went wrong.
I think I need to go through the Tuts from the start.
I do have experience in BASIC programming, but non at all at App building. I am still figuring out how all the parts and files fit together.
For instance, in your example, I changed you welcome.gif ( in the designer), saved it the layout under the same name. I I get te error message that i can not find welcome.gif .
When I have figured that out, i'll start with my own splash screen using you code as a guideline, and see what happens.
 

pluton

Active Member
Licensed User
Longtime User
Hi Hero
It is not welcome.gif. It is welcome.png

In designer just add image and then choose image under Image File.
If you stuck somewhere just ask.

Look at screenshot:

HERO.png
 

Hero post

Member
Licensed User
Longtime User
Newbee starting to understand

Thanks again, I feel stupid.
I completely missed the Panel properties part with the BitmapDrawable option. (it was set to ColorDrawable).
Changed it, compiled it, and now of course SUCCESS.
(by the way, the png <> gif was a typo)
Slowly Im getting a feel for b4a.
I find it better to comprehand that Eclipse. (and I am not a big Java fan)
 

sktanmoy

Active Member
Licensed User
Longtime User
I'm facing an issue with splash screen. The issue is:
Every time the screen is shown I rotate my device. I mean if I shake mt device a bit, screen is rotated and splash screen is shown.
Any solution?
 

ibra939

Active Member
Licensed User
Longtime User
wonderful:);)
 

Cableguy

Expert
Licensed User
Longtime User
I'm facing an issue with splash screen. The issue is:
Every time the screen is shown I rotate my device. I mean if I shake mt device a bit, screen is rotated and splash screen is shown.
Any solution?
add a flag to you activity_create(isfirsttime) or use the IsFirstTime flag to control (enable/disable) the showing of the splash screen
 
Top