Android Question How app was started

canalrun

Well-Known Member
Licensed User
Longtime User
Is this possible? And if so, what is the proper term (name) to use to describe it?

I would like to find out within the code how the app was started - was the app icon clicked or was the app started in response to a Quick Start Gesture.

The app is running on a Wear OS watch. I've already written and tested simple stuff written in B4A on the watch.

I would like the app to show a page if it was launched by clicking its icon, but just TTS the time and date if the app was launched by a Quick Start Gesture (wrist down-up).

Is there some variable like "UserOpened", maybe some way to look at starting intents, starting parameters, or something else?

I think I have seen apps that do different things depending on how they were started. Is there some other standard way to accomplish this?

Thanks,
Barry.
 

JohnC

Expert
Licensed User
Longtime User
Try adding this code in the Activity_Create and see if it displays different info for each different way you launch the app:
B4X:
Log(Activity.getStartingIntent.Action & " (" & Activity.GetStartingIntent.ExtrasToString & ")")
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
Thanks for pointing me in the right direction.

I modified your code a little bit to show me the Action, Extras, Data, and Flags.

B4X:
  Dim s1 As String
 
  s1 = "Action: " & Activity.getStartingIntent.Action
  s1 = s1 & CRLF & "Extras: " & Activity.GetStartingIntent.ExtrasToString
  s1 = s1 & CRLF & "Data: " & Activity.getStartingIntent.GetData
  s1 = s1 & CRLF & "Flags: " & Bit.ToHexString(Activity.getStartingIntent.Flags)
 
  Log(s1)

The Log output I get whether I launch from the Icon or a Quick Gesture is:

Action: android.intent.action.MAIN
Extras: no extras
Data: null
Flags: 10000000

Sometimes the flags are 10200000 when I launch from an icon. Looking at the Android docs I can't make heads or tails of the meaning of the flags but the "2" does not consistently show up when I launch from an icon and seems to be more dependent on how I previously exited the app (Back vs Home button).

I will keep investigating. Any ideas are very welcome.
 
Upvote 0
Top