D
Deleted member 30048
Guest
Every time I rotate the phone, the application consumes more and more ram
When the application is run for the first time, the app consumes 18 mb of ram. If I rotate the phone the app consumes 27 mb, if I rotate again 36 mb, 49, 57, 72, ...
The same thing happens when I open a layout, back to the main layout, open again the layout, back again to main layout. The app increasingly consumes more ram.
Android does this on purpose and then automatically clean the ram or the problem is mine because I do not clean the activity correctly?
This is my code:
My last question, I do not want to use several activities because every time I open a new activity reloads the ads, so my project loads the layouts in panels. Is correct the code I use to clean the layouts?
Thanks a lot and sorry for my english!
When the application is run for the first time, the app consumes 18 mb of ram. If I rotate the phone the app consumes 27 mb, if I rotate again 36 mb, 49, 57, 72, ...
The same thing happens when I open a layout, back to the main layout, open again the layout, back again to main layout. The app increasingly consumes more ram.
Android does this on purpose and then automatically clean the ram or the problem is mine because I do not clean the activity correctly?
This is my code:
B4X:
Sub Process_Globals
Dim Sound = True As Boolean
Dim Vibrate = True As Boolean
End Sub
Sub Globals
Dim Adview1 As AdView
Dim Panel1 As Panel
Dim Beep As PhoneVibrate
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Load the background
Dim Background As BitmapDrawable
If (Activity.height > Activity.Width) Then
Background.Initialize(LoadBitmap(File.DirAssets, "background.png"))
Else
Background.Initialize(LoadBitmap(File.DirAssets, "backgroundlandscape.png"))
End If
Background.Gravity = Gravity.FILL
Activity.Background = Background
'Create the menu
Activity.AddMenuItem("Sound", "SoundMenu")
Activity.AddMenuItem("Vibration", "VibrationMenu")
'Load principal screen
LoadLayoutToPanel("FirstLayout")
'Load ads
Load_Ads
End Sub
Sub Activity_Resume
End Sub
'User click to button1, open the second layout
Sub Button1_Click
LoadLayoutToPanel("SecondLayout")
End Sub
'User click to back in the second layout, open the first layout.
Sub Back_Click
LoadLayoutToPanel("FirstLayout")
End Sub
Sub Load_Ads
Adview1.Initialize2("Ad", "xxxx", Adview1.SIZE_SMART_BANNER)
Dim height As Int
If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
'phones
If 100%x > 100%y Then height = 32dip Else height = 50dip
Else
'tablets
height = 90dip
End If
Activity.AddView(Adview1, 0dip, 100%y - height, 100%x, height)
Adview1.LoadAd
End Sub
'LOAD A LAYOUT IN A PANEL.
Sub LoadLayoutToPanel (layout As String)
If Adview1.IsInitialized Then
RemoveView (Adview1) 'Remove all views except adview.
Else
Activity.RemoveAllViews 'Remove all views
End If
Panel1.Initialize("")
Activity.AddView(Panel1, 0, 0, 100%x, 100%y)
Panel1.LoadLayout(layout)
Panel1.SendToback 'If I don't send to back the panel. The panel hides the ads.
Panel1.Color = Colors.Transparent
End Sub
'REMOVE ALL VIEWS EXCEPT ADVIEW.
Sub RemoveView (V As View)
For i = 0 To Activity.NumberOfViews - 1
If Activity.GetView(i) <> V Then
Activity.RemoveViewAt(i)
End If
Next
End Sub
Sub SoundMenu_Click
If Sound == True Then
Sound = False
Else
Sound = True
End If
End Sub
Sub VibrationMenu_Click
If Vibrate == True Then
Vibrate = False
Else
Vibrate = True
Beep.Vibrate(700) 'Vibrate 700 ms.
End If
End Sub
My last question, I do not want to use several activities because every time I open a new activity reloads the ads, so my project loads the layouts in panels. Is correct the code I use to clean the layouts?
Thanks a lot and sorry for my english!