Android Question close an activity from a class

Discussion in 'Android Questions' started by pesquera, Mar 25, 2015.

  1. pesquera

    pesquera Active Member Licensed User

    Hi,
    I've done a class to improve and standarize my list views
    Into an Activity, I've defined a PanelView so that class does fill the views that I like into the Panel
    One of these views is a button to close the activity
    If into the class I do a call to a sub into that Activity, for doing an Activity.Finish all is fine
    But, I'm looking for a way to do that without define any sub into the Activity
    Is there a way to close an activity from a class?
    Thanks
     
  2. JordiCP

    JordiCP Well-Known Member Licensed User

    You will need to pass the activity as an argument when initializing the class

    This is an example of a class module that will close the activity after a timeout
    Code:
    'Class module
    Sub Class_Globals
    Dim myp As Activity   
    Dim t As Timer

    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize(Parent As Activity,temps As Long)

    myp=Parent
    t.Initialize(
    "T1",temps)
    t.Enabled=
    True
    End Sub

    Sub  T1_Tick
        t.enabled=
    False
        CallSubDelayed(Me,
    "closeActivity")
    End Sub

    Sub closeActivity
        myp.Finish
    End Sub
    and from your main module
    Code:
    Dim CL1 as CL_test  'the name of the class
    ...
    CL1.Initialize(
    Activity,5000)
     
    pesquera likes this.
  3. pesquera

    pesquera Active Member Licensed User

    Excellent! thanks :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice