Android Question Optimize code to save memory


Licensed User
Longtime User
I made a torch by using the screen and the flashlight. It's a simple project, but I noticed it spends more than 500 Kb when it's installed on the device.

#Region  Project Attributes
    #ApplicationLabel: Melight
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: true
    #IncludeTitle: false
#End Region

'Simple torch using the camera flash or the screen to provide light.
'I've commented it in english just to post a question (so forgive my bad english)

Sub Process_Globals
    Dim LED As Boolean                'Whether is selected Flash or screen
End Sub

Sub Globals
    Dim Control As Phone                'To set the maximum screen brightness
    Dim Eventos As PhoneEvents            'To measure the battery left
    Dim Camara As AdvancedCamera        'To swith the white LED on.
    Dim Panel1 As Panel                    'To manage the click event to toggle the light source
    Dim Panel2 As Panel                    'To let me initialize AdvancedCamera to use the flash light

    Dim Label1 As Label                    'To show the battery left
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")        'It has just two panels and a label

    AdaptaVistas                        'Set the views' initial status

    Dim Id As PhoneId

End Sub

Sub Activity_Resume
    Camara.Initialize(Panel2,"Camara")    'Initializes the AdvancedCamera
    Control.SetScreenBrightness(1)        'Sets the maximum screen brightness
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If LED Then    Camara.FlashOff            'If the LED was on, switches it off
    Control.SetScreenBrightness(0)        'Sets the screen brightness low
End Sub

Sub Camara_Ready (Success As Boolean)
    If Success Then
        If LED Then Camara.FlashTorch    'If LED function is selected, switches the LED on
    End If
End Sub

'To make the main panel full screen
Sub AdaptaVistas
End Sub

'Changes the light's source
Sub Panel1_Click
    If LED Then                                            'If the LED was ON
        Panel1.Color=Colors.ARGB(255,255,255,255)        '    switches the screen on
        Camara.FlashOff                                    '    and switches then LED off
    Else                                                'If the LED was OFF
        Panel1.Color=Colors.ARGB(0,0,0,0)                '    switches the screen off
        Camara.FlashTorch                                '    and switchess the LED on
    End If
    LED=Not(LED)                                        'Remembers the current selected light source
End Sub

'Shows the battery left
Sub Eventos_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
End Sub

I use the AdvancedCamera lib just to switch the LED flashlight on. Maybe it's an important part of the problem. In spain we say: "It's like killing flyes by using a cannon".

Is there a way to avoid the inclusion of unused parts of a library?

Thanks a lot, and congratulations for an amazing tool.


Licensed User
Longtime User
Upvote 0


Licensed User
Longtime User
OK, thank you.

I wanted to forget java, but I suppose that sometimes it will be impossible.
Well, I'll try to build and share that library... May God have mercy on our souls. :confused:

Upvote 0