Starting one app from another?

mjtaryan

Active Member
Licensed User
Longtime User
Is there a simple and direct way for an app (or service) to call, that is start, another app that is not currently running? I'm thinking of something like

StartApp(AppName As String, Activity As String)

The above asumes first that AppName is known and is installed.

Thanks.
 

Mahares

Expert
Licensed User
Longtime User
Did you have something like this in mind? I learned it from Erel. Replace packagename with your packagename:
B4X:
Dim MyIntent as Intent
MyIntent.Initialize(MyIntent.ACTION_MAIN, "")
MyIntent.SetComponent("packagename/.main")
StartActivity(MyIntent)
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Did you have something like this in mind? I learned it from Erel. Replace packagename with your packagename:
B4X:
Dim MyIntent as Intent
MyIntent.Initialize(MyIntent.ACTION_MAIN, "")
MyIntent.SetComponent("packagename/.main")
StartActivity(MyIntent)

A couple of questions:

1. Why the forward slash ("/")? Is it required?
2. Am I correct that ".Main" is the activity being called? That is, if I wated to call a different activity, I could replace ".Main" with ".AnotherAcivitiy"?

If the answer to number 2 above is that I am correct in my understanding, then I suppose this will do what I need.

I came across some similar but more involved code in another thread somewhere that called and listed the PackageManager and then listed the packages (I assume the user was to pick one to run). I don't need that. My need is much simpler.

Thanks.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Another question. In your example you have a line

MyIntent.Initialize(MyIntent.ACTION_MAIN,"")

What is "ACTION_MAIN" and does it have anything to do with the activity "Main" in the call to the pacage? If so, then should "_MAIN" be replaced with the activity name I want to start? Thanks so much.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I do not think that the MAIN in ACTION_MAIN you refer to has anything to do with the name of the app you are launching. There is ACTION_MAIN, ACTION_VIEW, etc. Here is a link to some code that launches a module with a name other than MAIN, but uses ACTION_MAIN in the intent.
Intent - Basic4android Wiki

B4X:
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_MAIN, "")
Intent1.SetComponent("com.google.android.youtube/.HomeActivity")
StartActivity(Intent1)
 
Upvote 0
Top