Android Question Activity Create not executed when app forced closed by users?

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I am confuse here, isn't it Activity Create always executed when App start?

I have app that runs on background via service.
First run was OK, Activity Create was executed.

But when app forced closed and then run again, it seem that on the second run, Activity Create not executed.

Here are my codes from main activity
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Log("created")
    Private DvId As Object
    DvId = SQLTbl.ExecQuerySingleResult("SELECT DEV_ID from M_DEV_ID")
    If DvId = Null Then
        Activity.LoadLayout("lyAgreement")
    Else
        btnAgree_Click
    End If
End Sub

Sub btnAgree_Click
    Private DvId As Object
    DvId = SQLTbl.ExecQuerySingleResult("SELECT DEV_ID from M_DEV_ID")
    If DvId = Null Then
        Private Id as int
        Id = GetDevId
        SQLTbl.ExecNonQuery2("INSERT INTO M_DEV_ID(DEV_ID) VALUES (?)", Array As Object(ID))
    End If
    Activity.Finish
    StartActivity(modMain)
End Sub

Is this normal or something wrong with the codes?
 

incendio

Well-Known Member
Licensed User
Longtime User
There is no such thing. It is possible that you are not seeing the logs. If you are running in release mode then you need to add #BridgeLogger: True
You can also switch to USB debug mode.
#BridgeLogger: True is already present, the log was showed its activities when app runs normally.

I even add ToastMessageShow at Activity Create sub, but this message and log window showed nothing.

I can reproduced the error. The app use FusedLocationProvider in the service.
Here are the steps that leads to that odd behavior
  1. Run app with GPS already turn on (App already has permission to access GPS)
  2. 'created' text appeared in Log windows & ToastmessageShow
  3. A few second later, manually turn off GPS
  4. In the service, there is a timer that runs every 30 secs, this timer checks if GPS is on or off
  5. If GPS is off, show Resolution Dialog to user, after Resolution Dialog showed, click OK to turn on GPS
  6. wait a few second later, then manually Forced close the app
  7. Run again the app, this time log window showed nothing & ToastmessageShow didn't show
The app still has a lots of bugs, but this shouldn't caused Activity Create in module Main not executed, right?

If app forced close manually via OS, is the background service also terminated?

This odd behavior looks like the service not terminated.
 
Last edited:
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I can't enter USB debug mode, though my phone already listed in adb command
B4X:
adb devices
List of devices attached
xxxxxx         unauthorized
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I have tried it & revoke usb debugging, so far no avail.

This phone is quite gives me trouble.

I need adb access not only for running B4a, but also need to run shell in adb in order to try to disable power management app.

This power management app kills WhatsApp's service.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I am not sure, using steps in post #5, seems that Activity Create did called, but the log text 'created' in sub Activity Create didn't show in the log windows. Why is that?

Here are the contents of logs windows using USB Debugging
B4X:
*** Service (starter) Create ***
service created
** Service (starter) Start **
service started
** Activity (modmain) Create, isFirst = true **
** Activity (modmain) Resume **
*** Service (tracker) Create ***
Tracker created
** Service (tracker) Start **
Tracker started
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Don't assume that the Main activity will always be the first activity to start. In this case an activity named modmain was started.
Isn't it Main activity should be the first activity to start when app executed for the first time?

I knew why in this case it was not the first to start. It was because this code
B4X:
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_WHEN_NEEDED

So when users intentionally force close/ force stop the app, B4A thought that this is the OS that killed the app, so service started the app again, skipped the Main Activity and jumped to the modMain activity.
 
Upvote 0
Top