Android Question How to open my app's activity from other app?

Riddle Ling

Member
Licensed User
I have two applications: App1 and App2.

App1 has an Activity named SearchLocation.

I added in Manifest.xml of App1:
B4X:
AddActivityText(SearchLocation,
    <activity android:name="tw.edu.kyu.md.app.tainanpark2a.SearchLocation" ></activity>
)

Now I use the following code in App2:
B4X:
Sub Button1_Click
    Dim i As Intent
    i.Initialize("", "")
    i.SetComponent("tw.edu.kyu.md.app.tainanpark2a/.Searchlocation")
    Try
        StartActivity(i)
    Catch
        ToastMessageShow("app intent not found.", True)
    End Try
End Sub

But cannot open App1's SearchLocation Activity,
The error log is as follows:

B4X:
Error occurred on line: 46 (Main)
android.content.ActivityNotFoundException: Unable to find explicit activity class {tw.edu.kyu.md.app.tainanpark2a/tw.edu.kyu.md.app.tainanpark2a.SearchLocation}; have you declared this activity in your AndroidManifest.xml?
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1855)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1546)
    at android.app.Activity.startActivityForResult(Activity.java:4284)
    at android.app.Activity.startActivityForResult(Activity.java:4231)
    at android.app.Activity.startActivity(Activity.java:4568)
    at android.app.Activity.startActivity(Activity.java:4536)
    at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:848)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5698)
    at android.widget.TextView.performClick(TextView.java:10846)
    at android.view.View$PerformClick.run(View.java:22557)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7231)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

How to open my App1's Activity from App2?
Thank!
 
Last edited:

Riddle Ling

Member
Licensed User
Ok, now is work.

I use the following code in Manifest.xml of App1:
B4X:
AddActivityText(SearchLocation,
<intent-filter>
       <action android:name="tw.edu.kyu.md.app.tainanpark2a.SEARCH_LOCATION" />
       <category android:name="android.intent.category.DEFAULT" />
</intent-filter>)

App2 code is modified as follows:
B4X:
Sub Button1_Click
    Dim i As Intent
    i.Initialize("tw.edu.kyu.md.app.tainanpark2a.SEARCH_LOCATION", "")
    
    Try
        StartActivity(i)
    Catch
        ToastMessageShow("app intent not found.", True)
    End Try
End Sub

Can now open App1's SearchLocation Activity from App2.
 
Upvote 0
Top