Android Question Delay when startActivity is used when app is paused by home key

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

I have a very strange behavior.

We have a PTT app, and it runs on all types of devices. Some devices have a PTT button built into them which we can use via intent handling. The PTT button triggers an intent which is received into a service(set in the manifest file) and when we get PTT down intent to call startactivity(main) and the app pops up instantly.

The above is generally true when the user press's the back key, however when the home key is pressed, that is a 3 second delay before the app pop's up.

some info: https://stackoverflow.com/questions...oid-home-key-and-back-key-and-their-behaviour

Any advice on this ?

Regards

John.
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
It sounds to me like the system (or some app like the launcher) is waiting to see if the user is going to do a double-tap of the home button before it decides what action to initiate because that device may offer the ability to do one action with a single tap of the home button, and a completely different action if it's double-tapped.

So, the delay is to give the user time to do that double-tap.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
It sounds to me like the system (or some app like the launcher) is waiting to see if the user is going to do a double-tap of the home button before it decides what action to initiate because that device may offer the ability to do one action with a single tap of the home button, and a completely different action if it's double-tapped.

So, the delay is to give the user time to do that double-tap.
Thanks for the suggestion JohnC, that's not really what the problem is, when the back key is pressed the activity is destroyed, and when the PTT button is pressed it is instant. Not so when the home key is pressed, and I have even put activity.finish in the activity_pause if userclosed is false.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
The above is generally true when the user press's the back key, however when the home key is pressed, that is a 3 second delay before the app pop's up.
so the debug log activity create/resume appear in the ide with a delay after 3 seconds?
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
so the debug log activity create/resume appear in the ide with a delay after 3 seconds?

Yes.

Log when PTT button pressed after Home Key is pressed
B4X:
** Receiver (svc_intents) OnReceive **
*** Service (svc_intents) Create ***
** Service (svc_intents) Start **
05/10/2019 13:32:51.539 - Atlas PTT - svc_intents(), Service_Start, INTENT com.sonim.intent.action.PTT_KEY_DOWN
05/10/2019 13:32:51.544 - Atlas PTT - svc_intents(), ACTION com.sonim.intent.action.PTT_KEY_DOWN, Main.APPSET.main_running=false
05/10/2019 13:32:51.548 - Atlas PTT - svc_intents(), StartActivity(svc_service) <- Starting Main from a service, tried this to see if it would improve performance, it did'nt
** Service (svc_intents) Destroy **
05/10/2019 13:32:51.641 - Atlas PTT - svc_intents(), Service_Destroy
05/10/2019 13:32:51.709 - Atlas PTT - svc_service(), starting main, startMain = true
** Activity (main) Create, isFirst = false **
05/10/2019 13:32:53.560 - Atlas PTT - mod_functions(), set_ShowWhenLocked
05/10/2019 13:32:53.565 - Atlas PTT - Activity_Create, FirstTime false
** Activity (main) Resume **
05/10/2019 13:32:53.569 - Atlas PTT - mod_functions(), set_ShowWhenLocked
05/10/2019 13:32:53.574 - Atlas PTT - Activity_Resume
05/10/2019 13:32:53.944 - Atlas PTT - svc_data(), sendMessage, PTT_KEY_DOWN
05/10/2019 13:32:54.022 - Atlas PTT - svc_data(), TextMessageReceived, text=PTT_KEY_DOWN_OK, fromContact=353168070000144
05/10/2019 13:32:54.378 - Atlas PTT - svc_data(), SendAudio
** Receiver (svc_intents) OnReceive **
*** Service (svc_intents) Create ***
** Service (svc_intents) Start **
05/10/2019 13:32:54.788 - Atlas PTT - svc_intents(), Service_Start, INTENT com.sonim.intent.action.PTT_KEY_UP
05/10/2019 13:32:54.791 - Atlas PTT - svc_intents(), ACTION com.sonim.intent.action.PTT_KEY_UP, Main.APPSET.main_running=true
** Service (svc_intents) Destroy **
05/10/2019 13:32:54.889 - Atlas PTT - svc_intents(), Service_Destroy
05/10/2019 13:32:54.985 - Atlas PTT - svc_data(), sendMessage, PTT_KEY_UP
05/10/2019 13:32:54.990 - Atlas PTT - svc_data(), StopSendingAudio

Log when PTT button pressed after Back Key pressed
B4X:
** Receiver (svc_watchdog) OnReceive **
*** Service (svc_watchdog) Create ***
** Service (svc_watchdog) Start **
05/10/2019 13:33:36.388 - Atlas PTT - svc_watchdog(), schedulecallback, API = 22, call back @ = 13:34:36
05/10/2019 13:33:36.393 - Atlas PTT - svc_watchdog(), call back using StartServiceAtExact()
** Service (svc_watchdog) Destroy **
** Receiver (svc_intents) OnReceive **
*** Service (svc_intents) Create ***
** Service (svc_intents) Start **
05/10/2019 13:33:36.407 - Atlas PTT - svc_intents(), Service_Start, INTENT com.sonim.intent.action.PTT_KEY_DOWN
05/10/2019 13:33:36.412 - Atlas PTT - svc_intents(), ACTION com.sonim.intent.action.PTT_KEY_DOWN, Main.APPSET.main_running=false
05/10/2019 13:33:36.415 - Atlas PTT - svc_intents(), StartActivity(Main)
** Activity (main) Create, isFirst = false **
05/10/2019 13:33:36.507 - Atlas PTT - mod_functions(), set_ShowWhenLocked
05/10/2019 13:33:36.511 - Atlas PTT - Activity_Create, FirstTime false
** Activity (main) Resume **
05/10/2019 13:33:36.517 - Atlas PTT - mod_functions(), set_ShowWhenLocked
05/10/2019 13:33:36.521 - Atlas PTT - Activity_Resume
** Service (svc_intents) Destroy **
05/10/2019 13:33:36.732 - Atlas PTT - svc_intents(), Service_Destroy
05/10/2019 13:33:36.970 - Atlas PTT - svc_data(), sendMessage, PTT_KEY_DOWN
05/10/2019 13:33:37.034 - Atlas PTT - svc_data(), TextMessageReceived, text=PTT_KEY_DOWN_OK, fromContact=353168070000144
05/10/2019 13:33:37.392 - Atlas PTT - svc_data(), SendAudio
** Receiver (svc_intents) OnReceive **
*** Service (svc_intents) Create ***
** Service (svc_intents) Start **
05/10/2019 13:33:37.841 - Atlas PTT - svc_intents(), Service_Start, INTENT com.sonim.intent.action.PTT_KEY_UP
05/10/2019 13:33:37.848 - Atlas PTT - svc_intents(), ACTION com.sonim.intent.action.PTT_KEY_UP, Main.APPSET.main_running=true
** Service (svc_intents) Destroy **
05/10/2019 13:33:37.941 - Atlas PTT - svc_intents(), Service_Destroy
05/10/2019 13:33:37.989 - Atlas PTT - svc_data(), sendMessage, PTT_KEY_UP
05/10/2019 13:33:37.993 - Atlas PTT - svc_data(), StopSendingAudio

Regards

John.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
this looks like a long delay
05/10/2019 13:32:51.709 - Atlas PTT - svc_service(), starting main, startMain = true
** Activity (main) Create, isFirst = false **
05/10/2019 13:32:53.560 - Atlas PTT - mod_functions(), set_ShowWhenLocked
what happens here in svc_service?
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
this looks like a long delay

what happens here in svc_service?


It just calls startactivity(main). The problem is the length of time it is taking for he activity to start, does not matter where it is called from. This delay only happens when
the user press the home key, when the user has pressed the back key, no problem !

I have only discovered this problem when one of our customers pointed it out. Need to find a solution really soon ...
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
if you add a log with time stamp in main activity create
it match this time then?
** Activity (main) Create, isFirst = false **
05/10/2019 13:32:53.560 - Atlas PTT - mod_functions(), set_ShowWhenLocked
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
if you add a log with time stamp in main activity create
it match this time then?
** Activity (main) Create, isFirst = false **
05/10/2019 13:32:53.560 - Atlas PTT - mod_functions(), set_ShowWhenLocked

Yes, mod_functions(), set_ShowWhenLocked is called from Activity_create so it is the same time
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The help for ExitApplication in B4A states: "...Activity.Finish ... lets the OS decide when the process is killed". That may cause the 5 second delay before you can push the button again. You could try
B4X:
If Not(UserClosed) Then ExitApplication
and use the Part 1 of this post (https://www.b4x.com/android/forum/t...application-after-a-crash.103858/#post-653319) to install your own default UncaughtExceptionHandler that lets the application exit without asking the user to retry starting the application again. That may get rid of the delay before you can push the button again.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Public Sub ExitApplication2
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Build.VERSION")
    If jo.GetField("SDK_INT")>15 Then
        Dim jo As JavaObject
        jo.InitializeContext
        jo.RunMethod("finishAffinity", Null)
    Else
        ExitApplication
    End If
End Sub
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i used Activity.Finish only if me not want goto this page after pressed the back key.
as example the login page again or settings after it was saved.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
I do not want to exit the application, see post #1. The application is connected to a server and the user may press the home key for what ever reason, but the app is still connected to the server.

I just want the PTT button press down to behave the same as when the user pressed the back button, that's all :)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Right now, your logging shows an extra step (svc_service) for the home button push that the back button push does not have. Is that for testing purposes only and even without this extra step you have a 3 second delay? Without svc_service, is the log the same (all the steps) for both back button and home button cases with the only difference being the delay? Also, does it matter what application is on top when the home button is pushed - is the PTT app always up on top or can others be? - trying to see if it is an issue with the PTT app or all apps (if others can be on top)
 
Upvote 0
Top