Android Question Empty Activity after long idle of smartphone

DaOel

Member
Licensed User
Longtime User
First of all I have read some quizes and read the guide about life cycle of activities.
Perhaps i did not read carefully enough, but the bug i am experiencing is not covered by one of the quizes or explanations.

Bug description:
---
App is started as usual. Smartphone is idle for several hours (for example over night). App is resumed but the layout shown is empty!
---
Remarks:
I only use variables defined as service global variables. (except of the buttons and EditText, they are declared in Sub Globals of the activity)
The following code solves the problem but there is always a notification displayed:

B4X:
Sub Service_Create
  
    nNotify.Initialize
  
    nNotify.Icon = "auto"
    nNotify.Light = True
    nNotify.SetInfo("Termi Service für Sicherungen", "Klicke um Termi zu öffnen", Main)
    nNotify.Sound=False
    nNotify.Vibrate=False

    Service.StartForeground(1,nNotify)

End Sub

I do not want a notification to be displayed however.


Without that idle time the problem does not occur. For example i kill the process manually but when resuming app activity is loaded correctly.
I also tested with developer options 'No Background Services' and switched between apps. This was also causing no problems.
It seems there is a problem caused with the idle time of several hours.

Any Ideas?
 
Last edited:

DaOel

Member
Licensed User
Longtime User
Thank you Jose and Erel for the fast reply.
@Jose:
Only the edittext and buttons are stored in sub global. It is no advantage for me to store the values of the edittext or buttons within a KVS. I just want the buttons and textfields to be visible after long idle time, such that the user can start working with app (all over again) after idle time. Correct me if i am wrong, but as far as i know it is sufficient to declare the buttons within Sub Globals. Everytime the Activity.LoadLayout is called it will initialize them again.

@Erel
I have seen the video already and there are also some quizes that illustrate that it is a common mistake. My Code looks like this at the start:

B4X:
Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("ChooseStudent")
    Activity.Title = "Schüler Auswahl"
   
       [...]
 
Upvote 0

DaOel

Member
Licensed User
Longtime User
Activity Pause and Resume look like this:

B4X:
Sub Activity_Resume
    RenderLocker
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub RenderLocker
   
    Dim bmpSettings As Bitmap
    If Starter.UserCode <> "" And Starter.UserCode <> "null" Then
        Starter.BlackLock = True
        bmpSettings.Initialize(File.DirAssets,"Schloss_Haken.png")
    Else
        Starter.BlackLock = False 
        bmpSettings.Initialize(File.DirAssets,"Schloss_Gold.png")
    End If

    btnLicense.SetBackgroundImage(bmpSettings)
   
End Sub
 
Upvote 0
Top