How to start an application from my other application?

How do I run an application from another application? (they will not be packed together)

- update

Manifesto of the second application:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.helloandroid"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloAndroid"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <activity android:name=".HelloAndroid">
            <intent-filter>
                <action android:name="com.example.helloandroid.HelloAndroid" />
            </intent-filter>
        </activity>

    </application>


</manifest>

I call it with

startActivity(new Intent("com.example.helloandroid.HelloAndroid"));

and he throws:

07-16 15:11:01.455: ERROR/Desktop(610): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.helloandroid.HelloAndroid }

Ralated:
How to run Android applications from another application

0
source share
2 answers

In the first application you will need to change AndroidManifest.xml. In particular, you are about to add a custom actionin intent-filterfor the action that you want to run somewhere:

<activity android:name="FirstApp">
  <intent-filter>
    <action android:name="com.example.foo.bar.YOUR_ACTION" />
  </intent-filter>
</activity>

Then in your second application, you use this action to trigger an activity:

startActivity(new Intent("com.example.foo.bar.YOUR_ACTION"));

As for your comments:

, "android.intent.action.MAIN" Eclipse

, , ... :

<activity android:name="FirstApp">
  <intent-filter>
    <action android:name="com.example.foo.bar.YOUR_ACTION" />
    <action android:name="android.intent.action.MAIN" />
  </intent-filter>
</activity>
+4

, .

, :

Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName( "PACKAGE NAME", "CLASS" ));
startActivity(intent);
+1

Source: https://habr.com/ru/post/1756211/


All Articles