Android Tutorial Collecting tips - Beginners wanted!

Status
Not open for further replies.
I want to collect useful tips for developers who are starting to develop with Basic4android.
I'm deeply familiar with Basic4android and therefore not always aware of difficulties that new users may encounter.
I would like to ask you to think for a moment about difficulties you encountered while getting started with Basic4android and write some tips that may help others who face the same difficulties.

Please start a new thread for any question. Only tips, examples and references should be posted here.
 

kingapps

Member
Licensed User
Longtime User
nice thread
i will bookmark this so i can always check the updates for beginner

im a newbie here and need to understand everything while learning
how B4A work for android apps development
 

sioconcept

Active Member
Licensed User
Longtime User
Easy Transition Panel

Hi all,

This is my contribution. This example can make a transition between 2 panels (or more of course).

All panel must have the same size.

Call it with the old panel in first (named home) and the new in second (named menu).
B4X:
ViewPanel(home, menu)

B4X:
Sub ViewPanel(OldName As Panel, NewName As Panel)
   Dim i As Int
   NewName.Left = NewName.Width
   NewName.Top = 0
   OldName.Left = 0
   OldName.Top = 0
   Do While NewName.Left > 0
      i = i + 1
      Sleep(1)
      OldName.Left = OldName.Left - i
      NewName.Left = NewName.Left - i
   Loop
   NewName.Left = 0
   OldName.Left = - OldName.Width
End Sub

Sub Sleep(Ms As Int)
   Dim Ti As Long
   Ti = DateTime.Now + (Ms)
   Do While DateTime.Now < Ti
      DoEvents
   Loop
End Sub

Special Thanks to HotShoe
 

duneplodder

Active Member
Licensed User
Longtime User
Use "Clean Files Folder"

I slowly realized that the apk created by my project was rather large (2.4MB).

It took a while, but found that at an early stage I had added four image files into my project, whilst I decided which to use for my splash screen. I had forgotten all about them.

Using Tools/Clean Files Folder in the IDE reduced my apk to 334kb!

May be as well to back the files up beforehand, as I don't think it backs them up anywhere.

Robert
 

tecevit

Member
Licensed User
Longtime User
Hi,

Dim dalgalar(dalgasayisi,11) '................... works ( all are numbers )
Dim dalgalar(dalgasayisi,11) As Int '........... works much faster

Do you think there is a calculation speed difference Int < Double < Float ?

Thanks for all the tips..
 
Last edited:

ELCHARO

Member
Licensed User
Longtime User
Common way to navigate a maps is

B4X:
For Each var As String In views_map.Keys         
  'try to delete more that 1 item and crash
Next

'you must use bottom code an not crash again.

B4X:
For i=views_map.Size - 1  To 0 Step -1           
' in this case delete NULL maps , but use as you like
        If views_map.GetKeyAt(i) =Null Then
             views_map.Remove(views_map.GetKeyAt(i))
        End If
Next
 

ELCHARO

Member
Licensed User
Longtime User
Textsize in views is a problem.
In button the padding (are forum examplescode) is necesary if you want to see bigger text in it.
Im working a lib to help with fonts. Work well, but need more tests and experince before deploy.
 

ELCHARO

Member
Licensed User
Longtime User
Save space line and clarity
B4X:
Dim Some As int : Some=10   ' declare and init in one line

if Some > 10 then  Some= 0   ' if in 1 line
 

ELCHARO

Member
Licensed User
Longtime User
For beginers.

Learn to create clases modules, split the code and encapsulated.

#region,#end region, are good but if you have a lot in one page are in problems.
 

ELCHARO

Member
Licensed User
Longtime User
I very new in this language.
In views using x% instead of others size methods work fine and fast for me.

For other part are the textsize. Are dificult,but try to find tips in the forum to "fit" text in views and padding views too.

Found working without a designer faster. Declare and initialize in code. But try to find the best to fit yours need.

You can "lie", declaring in designer, create del event functions and rename the views in code like you wont.
Add yourview.initialize and delete the layout designer.

For other way if you don't know this views items , the designer is a good tool to learn, methods,declaration and variables.
 

ELCHARO

Member
Licensed User
Longtime User
When you create and modify code can reverse the input. But sometimes if better to copy all code you are modifing
next select the copy and CTRL Q to comment.
If the modification fail, CTROL W return the copy code and delete ther modification.

Save the code with FILE/EXPORT as ZIP, when work as you like.
If introduce an "extrain" error , return to zip/safe code.
Better , viewing old code and seeing the "evolution" is ¿gracefully?
 

Guardian17

Active Member
Licensed User
Longtime User
When you add a Timer to your code, IMMEDIATELY place a "TimerX.Enabled = False" statement somewhere in your Activity_Pause Sub.

Timers do not stop operating on Activity_Pause automatically, such that, if you have an orientation change and you don't disable ALL of your active Timers, a Timer_Tick event will occur after you've re-established your screen in the new orientation. This "unexpected" Timer Tick may then occur when views that are associated with that timer tick have not been re-loaded in a layout or otherwise re-initialized, leading to an error.

I have known about the need to disable timers during Activity_Pause since starting a game App I've been working on for the past two years, and there were two timers that I use throughout the App that I did disable in Activity_Pause. However, with the addition of an end-of-game panel that also uses a timer as a score-tallying mechanism, (which I added very recently), I had forgotten to disable that timer in Activity_Pause. While going through my final debugging of the App before putting it (soon) on the market, "all of a sudden" I was getting errors for an un-initialized panel during that end-of-game operation if I rotated the device while that Tally Panel was being shown. The error does not give any information about the associated Timer that has fired which eventually results in this kind of error. And the error seemed to not make any sense because the panel that was being cited in the error had nothing to do with the information/panels that were currently on the screen.

Stated another way, if you are receiving errors about un-initialized objects after an orientation change, always check that ALL Timers that you use get disabled in Activity_Pause.
 
Last edited:

Troberg

Well-Known Member
Licensed User
Longtime User
Is there ever any circumstance when it is sensible to leave a timer enabled when an activity is paused? I can't see any.

In that case, perhaps timers should be automatically disabled on pause by the compiler?
 

KMatle

Expert
Licensed User
Longtime User
Package name:

Creating a new (or the first) project you have to give a package name under "build configurations". This represents the unique name for your app. 2 apps having the same name are considered as the same app which will lead to problems (f.e. the installed app is overwritten by another or the installation fails).

Unique means unique (worldwide). A company would choose it like this: com.companyname.appname. So if you have a website, put the name of it in you package name to be unique: de.meier.meyerapp (for a german page). If you don't have one, you could choose de.meiermichaeljohn.myapp

If you want to publish it you need to sign your app under "private sign key". This is like your signature. Don't forget the password. Store it at a safe place.

You only need ONE key (like you only have ONE signature). At the beginning I thought that every app I've made needed it's own key :D
 

edm68

Member
Licensed User
Longtime User
"Missing Keyword: end sub" error
Hi,
Just wanted to mention that missing a space can cause a problem.
For example:
B4X:
    If edtMnmAIn.Text<>""Then
Creates a "Missing Keyword: end sub" error
However,
B4X:
If edtMnmAIn.Text<>"" Then
compiles okay.
I am using V3.80, so don't know if it's changed in newer versions.
 
Status
Not open for further replies.
Top