Android Question rounting message from activity to object

Roberto P.

Well-Known Member
Licensed User
Longtime User
hello to all
I am creating an object that allows me to create a common basis for the activity (why B4A not support class inheritance).

I need help to send messages from the menu class activity linked object.

In practice, the object I create the menu of Activity but I want the message "remain" in the subject without having to send in the same class.

B4X:
Sub Class_Globals

    Private m_Parent As Activity
       
    Private     bar                     As StdActionBar
    Private bmpNuova, bmpChiudi, bmpSalva, bmpMenu As Bitmap
       
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(aActivity As Activity, aSubTitle As String)

    m_Parent        =    aActivity
   
    CreateUI

End Sub
' creo interfaccia utente
Sub CreateUI

    bar.Initialize("bar")
    bar.ShowUpIndicator     = True
   
   
    bmpChiudi                         = LoadBitmap( File.DirAssets, "img/indietro.png" )
    bmpNuova                            = LoadBitmap( File.DirAssets, "img/nuovo.png" )
    bmpSalva                            = LoadBitmap( File.DirAssets, "img/salva.png" )
   
   
    m_Parent.AddMenuItem3("Nuova Anagrafica",        "cmdNuova",                bmpNuova,     True)
    m_Parent.AddMenuItem3("Salva Documento",        "cmdSalva",                bmpSalva,     True)
    m_Parent.AddMenuItem3("Chiudi",                            "cmdChiudi",            bmpChiudi,     True)
   
   
End Sub
Sub bar_ButtonClicked
    m_Parent.Finish
End Sub
Sub cmdChiudi_Click
        m_Parent.Finish
End Sub
Sub cmdNuova_Click
    Msgbox("new", "new")
End Sub

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

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 m_BaseClass As CActivityBase

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
   
    m_BaseClass.Initialize(Activity, "title")
    Activity.LoadLayout("a")


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub cmdChiudi_click
       
    Msgbox("close", "close")
   
    'note
    'I wish that this message is sent to the object and not the activity or object that is turned on automatically.
   
   
End Sub
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
hello Erel,
thanks for the first tip and the response. I will do otherwise.

Sorry if I insist with the same question: do you believe that there will be the ability to manage the inheritance with B4A? Or the ability to create a base class in Java a personalized Activity from which to create the Activity of B4A? Even in future versions?

Thanks again.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Currently it is not possible to create a base class for the activity in B4A. It might be possible with Java and the Extends attribute.
I don't recommend you to use it as this is not the standard way to implement activities in B4A and will most probably do more harm than good.

It should be simple to create a class that implements the common features in all the activities. All you need to do is to delegate two or three event subs to the class (all the menu items can use the same event sub).
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
hello Erel,
I wanted to avoid having to implement the same for each sub activity. I will do so, until it will be available otherwise.

thanks for the reply.
 
Upvote 0
Top