I am trying to launch a new activity from within an existing activity however I get an activity not found exception.
Here is a stripped back version of my code and the logcat error. Any help would be really appreciated.
MainActivity
public class MainActivity extends FragmentActivity {
/* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(new Intent(this, TermsAndConditions.class));
}
....
}
NewActivity
public class TermsAndConditions extends Activity{
/* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.terms_and_conditions);
}
}
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:screenOrientation="sensorLandscape">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="@string/app_name" android:name=".TermsAndConditions"></activity>
</application>
</manifest>
Logcat
04-02 16:48:43.255: E/AndroidRuntime(20856): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.app/com.example.app.TermsAndConditions}; have you declared this activity in your AndroidManifest.xml?
<activity android:label="@string/app_name" android:name="com.example.app.TermsAndConditions"></activity>
and clean
your project,
Hope this help you.
The problem is, you've told the Main Activity to send the intent but you haven't told the Terms and Conditions activity to receive the intent. You do that by, in the onCreate method in the Ts and Cs page go getIntent()
after setContentView
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.