Android Question Close an activity from a class?

Juan Luis Lopez

Member
Licensed User
Longtime User
Hi!
Im trying to close an activity from a class

This is the Class Code:

B4X:
Sub Class_Globals
    Dim Duracion As Int
    Dim Imagen As BitmapData
    Dim ActivitySiguiente As Activity   'The next activity
    Dim ActivityActual As activity       'The current activity
    Private Contador As Int                'A counter
    Dim X As Float
    Dim Y As Float
    Dim Ancho As Float
    Dim Alto As Float
    Dim GameViewP As GameView     'The Gameview where im going to draw the splash
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(IX As Float, IY As Float, IAncho As Float, IAlto As Float,InicialDuracion As Int,InicialImagen As String,InicialActivityActual As Activity,InicialActivitySiguiente As Activity)
'Se asignan los valores a los atributos
Duracion=InicialDuracion
Imagen.Bitmap= LoadBitmap(File.DirAssets,InicialImagen)
ActivityActual= InicialActivityActual
ActivitySiguiente= InicialActivitySiguiente
X=IX
Y=IY
Ancho=IAncho     'width
Alto=IAlto           'height
Imagen.DestRect.Initialize(x,y,x+Ancho,y+Alto)
GameViewP.BitmapsData.Add(Imagen)
End Sub

Sub Render()
'So when the counter reaches the limit (Duracion) start the next activity and close the current
Contador= Contador+1
If Contador >= Duracion Then
      StartActivity(ActivitySiguiente)
      ActivityActual.Finish
      Contador= Duracion
End If
End Sub

I want to use this for a splash screen so in Main activity i create a new splashscreen object and use as a parameter the destination activity (Which activity is going to run) and the current activity (wihich i want to close)

I use this line on Main Activity and this is the line of the error at compiling time.

B4X:
FondoSplash.Initialize(0,0,100%x, 100%y,100,"FondoJW.png",Me,MainMenu)

I think the problem is the "Me" used as a parameter. in the error log it says something like "mostCurrent.activityBA"


LOG:
Parsing code. 0.02
Compiling code. 0.28
Compiling layouts code. 0.00
Generating R file. 0.14
Compiling generated Java code. Error
B4A line: 37
FondoSplash.Initialize(0,0,100%x, 100%y,100,\
javac 1.6.0_34
src\b4a\example\main.java:293: inconvertible types
found : java.lang.Class<capture#458 of ?>
required: anywheresoftware.b4a.BALayout
mostCurrent._fondosplash._initialize(mostCurrent.activityBA,(float) (0),(float) (0),(float) (anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (100),mostCurrent.activityBA)),(float) (anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (100),mostCurrent.activityBA)),(int) (100),"FondoJW.png",(anywheresoftware.b4a.objects.ActivityWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.ActivityWrapper(), (anywheresoftware.b4a.BALayout)(main.getObject())),(anywheresoftware.b4a.objects.ActivityWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.ActivityWrapper(), (anywheresoftware.b4a.BALayout)(mostCurrent._mainmenu.getObject())));
^
1 error
--------------------------------------------------------------------------------


Does anyone know how to fix it? or how to close an activity from a class?
I read a post about closing an activity from another but i dont want to use the process globals flag
 
Last edited:
Top