Android Question Main activity doesn't refresh at the same time

pantaraf

Member
Licensed User
Longtime User
Hi,
I'm having a problem with my main activity.
Weirdest part: it happens only on a eeepad Transformer (Tegra 2 based) 4.0.3. I'm developing and testing on a Nexus 7 and on a cheap LG L5 mobile as well none of the two show this defect.
Is this a known bug/limitation of the Tegra2 chipset?
It's made up of 12 button each one of them is loaded with the very same png image, all of them are positioned by designer script. Each button when pressed starts a different activity, each of them with a different layout. When the called activity ends by user action or by its onw logic, it returns to its parent Activity (main). At this point the main activity shows up but the 12 button are not redrawn in a whole, it's not always the case though. Sometimes it gets refreshed in a whole, sometimes 2 or 3 buttons show up followed by the remaining ones after, let's say, 200 or 300 ms, sometimes all, but 2 or 3, buttons show up immediately follwed by the remaining ones after a while. I've tried to use Activity.Invalidate on main Activity_Resume, but no luck. I've tried to remove bitmap from all the 12 buttons, but the problem remains.

Thank you.
Raffaele
 
Code: Copy
Sub Activity_Create(FirstTime As Boolean)
   Dim SQL As SQL
   
  If(FirstTime) Then
    cntSplash=0
    tmrSplash.Initialize("tmrSplash",4000)
    tmrSplash.enabled=True
    Activity.LoadLayout("Splash") 'Shows a splash png
    If(File.Exists(File.DirDefaultExternal,"DB.s3db")) Then
      SQL.Initialize(File.DirDefaultExternal,"DB.s3db",False)
    Else
      DBUtils.CopyDBFromAssets("DB.s3db")
      SQL.Initialize(File.DirDefaultExternal,"DB.s3db",False)  
    End If
   Else
     Activity.LoadLayout("Main")
     'ScaleText 'Sub used to set the right font size of each button text depending on screen resolution (in this moment disabled)
   End If
End Sub

When the timer expires then the Splash layout is removed and main loaded:
Code: Copy
  Activity.RemoveAllViews  
  Activity.LoadLayout("Main")
  'ScaleText

Thank you.
Raffaele
 
Upvote 0
Do you mean in each activity Pause sub?

Code: Copy
Activity.RemoveAllViews
Activity.Finish

Should I check for UserClosed? Or is it right this way?

Thanks.
Raffaele
 
Upvote 0
Sorry, I'm missing something... :D
Do you mean all the calls to Activity.RemoveAllViews in the main activity?
Code: Copy
Sub tmrSplash_Tick
  tmrSplash.Enabled=False
  Activity.RemoveAllViews
  Activity.LoadLayout("Main")
End Sub
This is the only place where I call it.
Should I call it even in Activity_Pause in the Main activity?

Thanks.
Raffaele
 
Upvote 0
Update:
I've put this code into main resume
Code: Copy
Sub Activity_Resume
  If(cntSplash>0) Then
     Activity.LoadLayout("Main")
     'ScaleText
     Activity.Invalidate
   End If
End Sub

Things are a little bit better now, even if from time to time two or three buttons appear with a delay (as above, I can quantify it in less than half second). The if is used to avoid loading "Main" layout while the splash is still showing. The variable is set to 1 when the timer expires.

Raffaele
 
Upvote 0
Code: Copy
#Region  Project Attributes
   #ApplicationLabel: ApiDroid
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
  Dim tmrSplash As Timer
  Dim SQL As SQL
  Dim lvapiari_position As Int
  Dim lvapiari_value As Object
End Sub

Sub Globals
   Private btnMeteo As Button
   Private btnQRCode As Button
   Private btnApiari As Button
   Private cntSplash As Int
   Private btnArnie As Button
   Private btnRegine As Button
   Private btnRaccolti As Button
   Private btnVisite As Button
   Private btnAttività As Button
   Private btnPrefs As Button
   Private btnFioriture As Button
   Private btnInfo As Button
   Private btnFamiglie As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If(FirstTime) Then
    lvapiari_position=-1
    lvapiari_value=Null
    cntSplash=0
    tmrSplash.Initialize("tmrSplash",4000)
    tmrSplash.enabled=True
    Activity.LoadLayout("Splash")
    If(File.Exists(File.DirDefaultExternal,"ApiDroidDB.s3db")) Then
      SQL.Initialize(File.DirDefaultExternal,"ApiDroidDB.s3db",False)
    Else
      DBUtils.CopyDBFromAssets("ApiDroidDB.s3db")
      SQL.Initialize(File.DirDefaultExternal,"ApiDroidDB.s3db",False) 
    End If
   Else
    Activity.LoadLayout("Main")
    'ScaleText
   End If
End Sub

Sub Activity_Resume
  If(cntSplash>0) Then
     Activity.LoadLayout("Main")
     'ScaleText
     Activity.Invalidate
   End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   Activity.RemoveAllViews
End Sub

Sub btnMeteo_Click
   StartActivity(MeteoActivity)
   CallSub(MeteoActivity,"")  
End Sub

Sub btnQRCode_Click
   StartActivity(QRCodeActivity)
   CallSub(QRCodeActivity,"")  
End Sub
Sub btnApiari_Click
   StartActivity(Apiari)
   CallSub(Apiari,"")  
End Sub

Sub tmrSplash_Tick
  cntSplash=1
  If(cntSplash>0) Then
    tmrSplash.Enabled=False
    Activity.RemoveAllViews
    Activity.LoadLayout("Main")
    'ScaleText
  End If
End Sub
Sub btnArnie_Click
  StartActivity(Arnie)
  CallSub(Arnie,"")  
End Sub
Sub btnFioriture_Click
  StartActivity(Fioriture)
  CallSub(Fioriture,"")    
End Sub
Sub btnVisite_Click
  StartActivity(Visite)
  CallSub(Visite,"")  
End Sub
Sub btnRegine_Click
  StartActivity(Regine)
  CallSub(Regine,"")  
End Sub

Sub ScaleText
  Dim btnCanvas As Canvas
  Dim testo As Float
  Dim fontsize As Int
  Dim Btns() As Button

  Btns = Array As    
  Button(btnApiari,btnArnie,btnVisite,btnFamiglie,btnRegine,btnMeteo,btnQRCode,btnFioriture,btnAttività,btnRaccolti,btnPrefs,btnInfo)
  btnCanvas.Initialize(Activity)
  For i=0 To 11
    testo=btnCanvas.MeasureStringWidth(Btns(i).Text,Typeface.SANS_SERIF,Btns(i).TextSize)
    fontsize=Btns(i).TextSize
    Do While(testo<(Btns(i).Width/1.76))
      fontsize=fontsize+1
      testo=btnCanvas.MeasureStringWidth(Btns(i).Text,Typeface.SANS_SERIF,fontsize)
    Loop
    Do While(testo>(Btns(i).Width/1.76))
      fontsize=fontsize-1
      testo=btnCanvas.MeasureStringWidth(Btns(i).Text,Typeface.SANS_SERIF,fontsize)
    Loop
    Btns(i).TextSize=fontsize
  Next
End Sub

Sub btnFamiglie_Click
  StartActivity(Famiglie)
  CallSub(Famiglie,"")  
End Sub
 
Upvote 0
I have to call it from each activity because otherwise I run into "Downsampling image due to lack of memory", I use three little png to build up secondary activities layout using several panels (maybe 20 each activity). But going back and forth from and to main make me run into the problem, both in debug and release, the latter shows the problem later though.

Thank
Raffaele
 
Upvote 0
I'm using the splash png (released after 4 seconds), the weathericons from ICOSWorldForecast, and five more pngs for layout.
The weather icons are loaded using viewMeteo.SetBackgroundImage(Meteonow.CCIcon).
The layout pngs are loaded at design time in each view.
What is the problem in using RemoveAllViews? Memory leakage? Slow down?
The png are slightly bigger (not that much) than the actual size they get when they are into the views.
Would resizing them help to resolve the "Downsampling image due to lack of memory"? I've searched a lot amongst the forum threads but I couldn't figure out where the problem is and how to fix it.

Thank you.
Raffaele
 
Upvote 0
The problem with RemoveAllView is that it is more difficult to handle all the cases correctly. For example your code doesn't handle the case where the user presses on the home button and then returns to the app. Activity_Create will not be raised in this case.

Make sure that all the images are not larger than they should be. You can actually make them smaller and let them stretch a bit.
 
Upvote 0
Thanks. I've removed all the grapichs from designer, and now they are loaded runtime using LoadBitmapSample. I've removed all the calls to RemoveAllViews, except the one regarding the splash panel. The "Downsampling image due to lack of memory" is gone.
The weirdness on the eeepad still remains. I'll try to take care of it later, now I have to go further in development.

Thanks a lot!
Raffaele
 
Upvote 0
Back
Top