Error running second Activity: The activity must be exported or contain an intent-filter

匿名 (未验证) 提交于 2019-12-03 02:20:02

问题:

I cant seem to launch my application. It gives me an error like this: "Error running second Activity: The activity must be exported or contain an intent-filter".

Is there anything wrong with my manifest?

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="sg.edu.rp.g913.mymakeuppouch">       <application         android:allowBackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsRtl="true"         android:theme="@style/AppTheme">         <activity android:name=".MainActivity">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                  <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>         <activity android:name=".secondActivity">         </activity>     </application>  </manifest> 

回答1:

Put android:exported="true" in the <activity> tag

<activity android:name=".secondActivity"     android:exported="true"> 


回答2:

You should set the Run>edit configuration to the desired launcher activity and give the intent filter at the manifest to the correct activity

below is the error creating situation

<application     android:allowBackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:supportsRtl="true"     android:theme="@style/AppTheme">     <activity android:name=".MainActivity">          <intent-filter>             <action android:name="android.intent.action.MAIN" />              <category android:name="android.intent.category.LAUNCHER" />         </intent-filter>      </activity>     <activity android:name=".Page_2">     </activity> </application> 

Image showing incorrect configuration

correct configuration and code are given below to run Mainactivity as launcher activity

<application         android:allowBackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsRtl="true"         android:theme="@style/AppTheme">         <activity android:name=".MainActivity">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                  <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>         <activity android:name=".Page_2">         </activity>     </application> 

corrected configuration window



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!