Android Question Detect APP's Launch Method

Startup

Active Member
Licensed User
I want my APP to behave differently depending on whether the user launched it by pressing the launcher icon or by turning on the phone (The APP has a a service module which has StartAtBoot set to True). Is there some way (code) to detect which way it was started?
 

Erel

Administrator
Staff member
Licensed User
Yes.
1. Make sure to not use the starter service as the service that starts at boot. Use a different service.
2. When that service starts you can check the StartingIntent:
B4X:
Sub Service_Start (StartingIntent As Intent)
   If StartingIntent.IsInitialized And StartingIntent.Action = "android.intent.action.BOOT_COMPLETED" Then
     'start at boot
   End If
End Sub
 

Startup

Active Member
Licensed User
Yes.
1. Make sure to not use the starter service as the service that starts at boot. Use a different service.
2. When that service starts you can check the StartingIntent:
B4X:
Sub Service_Start (StartingIntent As Intent)
   If StartingIntent.IsInitialized And StartingIntent.Action = "android.intent.action.BOOT_COMPLETED" Then
     'start at boot
   End If
End Sub
Thanks Erel, but this is not clear to me. I am (as you say to) using a different service other than the starter service. Do I put the code you wrote here in that service or the starter service? Then what. How do I "check the StartingIntent" which I assume will tell me whether the APP was started by the user pressing the launcher icon or turning on the phone?
 

DonManfred

Expert
Licensed User
Do I put the code you wrote here in that service or the starter service?
You put this in the other service which you set to startatboot
How do I "check the StartingIntent" which I assume will tell me whether the APP was started by the user pressing the launcher icon or turning on the phone?
Erel has posted the code you need to use in the other service.
and you quoted it!
 

Startup

Active Member
Licensed User
You put this in the other service which you set to startatboot

Erel has posted the code you need to use in the other service.
and you quoted it!
Thanks for your reply. Apparently I am clueless as to something which should be obvious to me but is not or maybe I'm not asking my question clearly. I've attached a very simple example of an APP which can be launched by pressing the launcher icon or by turning on the phone. It contains Erel's code in a service (not Starter) which is set to startatboot. I would like it to display a message indicating whether it was started by pressing the launcher icon or by turning on the phone. Can you tell me what to add to the program to make it do this?
 

Attachments

Top