简体   繁体   中英

How to launch a certain activity of an Android app

I would like to launch, from my app, two specific activities A_Activity and B_Activity from apps Aapp and Bapp I inserted two buttons and in the two OnClickListener I wrote

Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("com.Acompany.Aapp.A_Activity");
ctx.startActivity(intent);

Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("com.Bcompany.Bapp.B_Activity");
ctx.startActivity(intent); 

Moreover I added to AndroidManifest.xml the following lines

<activity
    android:name="com.Acompany.Aapp.A_Activity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.Acompany.Aapp.A_Activity" />
    </intent-filter>
</activity>
<activity
    android:name="com.Bcompany.Bapp.B_Activity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.Bcompany.Bapp.B_Activity" />
    </intent-filter>
</activity>

But my app crashes and in the logcat I read "No Activity found to handle Intent" Where is my mistake?

EDIT: More precisely the two activities are not in my own app

Try like this. For your home activity(first launch activity) do like this in your manifest file.xml

<activity
    android:name="com.Acompany.LaunchHomeActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.Acompany.LaunchHomeActivity" />
    </intent-filter>
</activity>
<activity android:name="com.Acompany.Aapp.A_Activity">

</activity>
<activity android:name="com.Bcompany.Bapp.B_Activity">

</activity>

don't include <intent-filter> to all activities

More precisely the two activities are not in my own app

You should investigate target app's manifest file first, to check if these activities are available to others by being exported or offering publicly accessible intent filters. It looks you may simply be not allowed to do what you attempt to.

Intent intent = new Intent(myFirstClass.this, MySecondClassA.class);
startActivity(intent);

Class B

Intent intent = new Intent(myFirstClass.this, MySecondClassB.class);
startActivity(intent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM