Android Question Activity "Auto Resume" Problem

Marcos Alves

Well-Known Member
Licensed User
Longtime User
I have a very strange problem here that is clearly connected with the Android Version (6) and device (BLU Studio XL2), because doesn't happen in Samsung (Android 4), but I really could be more comfortable if could identify and fix because I really don't know if will happen with other combinations of Android and Device... so, let's go:

Imagine that I have two activities: contatos and indicacoes . In contatos I have the code calling indicacoes :
B4X:
Sub lbl4_Click
    
    StartActivity(indicacoes)
    
End Sub

And in contatos also, in Resume:

B4X:
Sub Activity_Resume

    Dim DatabaseCompleted = Kvs.Get("database_completed")
    If DatabaseCompleted = "done" Then
        If CargaCompleta Then
            ULV.RefreshContent
        Else
            Sql1.Initialize(File.DirInternal,"clubdata.db",True)
            lbl5.Visible = False
            Dim Query As String
            Dim Cursor1 As Cursor
        
            Query = "select ordem from contacts where sms_sent = 'Y' or sms_sent = 'N' order by name"
            Cursor1 = Sql1.ExecQuery(Query)
            Dim I As Int
            For I = 0 To Cursor1.RowCount - 1
                Cursor1.Position = I
                ULV.AddItem("ContactItem",Cursor1.GetInt("ordem"))
            Next
            CargaCompleta = True
            CancelScheduledService(sms_batch)
            Kvs.Put("smscontatosbatch","ongoing")
            StartService(sms_batch)
        End If
        
    End If

End Sub

The code runs without any error...

In indicacoes I have the code calling contatos:

B4X:
Sub lbl2_Click
    
    StartActivity(contatos)
    
End Sub

... and in indicacoes RESUME:

B4X:
Sub Activity_Resume
    
    Dim Query As String
    Dim Cursor1 As Cursor
    ULV.ClearContent
    
    Query = "select id from indicacoes order by razaosocial asc"
    Cursor1 = Sql1.ExecQuery(Query)
    If Cursor1.RowCount > 0 Then
        lbl5.Visible = False
        Dim I As Int
        For I = 0 To Cursor1.RowCount - 1
            Cursor1.Position = I
            ULV.AddItem("IndicacoesItem",    Cursor1.GetInt("id"))
        Next
    End If

End Sub

In BLU device, sometimes when switching between activity contatos and indicacoes the target automatically pauses... and if I call the app again from launcher the activity is resumed (wasn't closed, was really resumed without any request). The log says:

B4X:
Logger connected to:  BLU Studio XL 2
--------- beginning of system
--------- beginning of main
** Activity (contatos) Resume **
** Activity (contatos) Pause, UserClosed = false **
** Activity (indicacoes) Resume **
** Activity (indicacoes) Pause, UserClosed = false **
** Activity (indicacoes) Resume **
** Activity (indicacoes) Pause, UserClosed = false **
** Activity (contatos) Resume **
** Activity (contatos) Pause, UserClosed = false **
** Activity (indicacoes) Resume **
** Activity (indicacoes) Pause, UserClosed = false **
** Activity (contatos) Resume **
** Activity (contatos) Pause, UserClosed = false **

We can see indicacoes Pause... contatos Resume... and then... Pause??? Why?
It's very strange and I'm afraid that is something that eventually could happen in other devices. I can't imagine how to prevent from happening, as there is no code line calling that activity Pause (and happens only sometimes)... a detail: the automatic pause occurs when touching any point of activity panel. Any!

Suggestions about what could be happening are welcome... the challenge is launched!:)
 

nobbi59

Active Member
Licensed User
Longtime User
Seems really strange to me, just a guess but maybe youre running out of memory?
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Try closing an activity before you start the new one
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hi @Erel . No, I'm not using HttpJob or CallSubDelayed - but even if was using the target activity of callsubdelayed should be started when resuming the other activity no ? And more: if that was the problem, should happen in emulator and Samsung devices also...

It's important to notice two facts:

- The problem occurs only in BLU Studio XL2 (or in every Android 6, I don't have other device with this version of Android to test) - Samsung (SMT-216 - Android 5.1.1. ) works fine. Emulator also.
- The automatic Pause occurs only when touching any point of activity after switch activities. The pause trigger is the activity panel touch (but there is no code in activity panel touch event)

And more: there is no activity remaining on screen. The app is sent entirely to background. No destination activity of an hypothetical direct or service started delayed call...

My concern is: is this an insulated problem caused by the combination of device and SO or will happen in any Android V6 ? And, more important: how to fix? How to intercept the event that is causing the Activity pause?

It's important to say also that is really a Pause... when touching a row of a listview to select this and the automatic pause happens, calling again the app from launcher the row is selected, what means that activity wasn't finished and app didn't crash - the event was a real pause.
The reality is: I could ignore this and go ahead but I don't like to have my apps doing things those I didn't programmed and I don't know why (I think that it's the same for you @Erel , doesn't it? :)). Then, I have a strong desire to find the cause and fix.
 
Last edited:
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Try closing an activity before you start the new one
Hi,
I could try but it's not interesting because every time that activity is created I have an intensive access to local database to construct a list that sometimes has more than 1000 rows. Then, in this case, it's a good idea to preserve the activity paused in background as long as possible.
 
Last edited:
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Seems really strange to me, just a guess but maybe youre running out of memory?
no, there is no error. The log that I posted is complete.. You can see. Pause A ... start B ... pause B start A... Pause A Start B....... Pause B .. Start A... Pause A...(???)
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
If you can reproduce it in a small project then upload the project and we can better help you.
Thanks @Erel . Give me some time because I need to finish this one and if I stop now I will not attend the agenda ... probably in two or three days I can do this and will post in this thread. I think that, depending on the results, could be related to some bug that can impact many other apps in some specific combination of SO and device...
 
Upvote 0
Top