Reputation:
I am attempting to use the onBackPressed() method provided by android in order to
The class that I am using the onBackPressed()
method:
import com.interviewme.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Preparing extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preparation);
}
@Override
public void onBackPressed() {
Intent t = new Intent(this, Menu.class);
startActivity(t);
}
}
The part of the manifest file where I am trying to go back to:
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The full manifest file of the app:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.interviewme"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.interviewme.Splash"
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:name="com.interviewme.Play"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.PLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.interviewme.Result"
android:label="@string/title_activity_result" >
</activity>
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.interviewme.menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.interviewme.About"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.interviewme.InterviewTips"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.interviewme.Preparing"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
The error log from logcat:
05-09 08:09:43.420: E/AndroidRuntime(1741): FATAL EXCEPTION: main
05-09 08:09:43.420: E/AndroidRuntime(1741): Process: com.interviewme, PID: 1741
05-09 08:09:43.420: E/AndroidRuntime(1741): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.interviewme/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
05-09 08:09:43.420: E/AndroidRuntime(1741): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
05-09 08:09:43.420: E/AndroidRuntime(1741): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
http://androidmanifest.xml/
androidmanifest.xml
I notice that It states ActivityNotFound
, however this Activity
is definitely within my app, is it named incorrectly in manifest?
Upvotes: 0
Views: 1054
Reputation: 38439
Error showing because below:-
import android.view.Menu;
Intent t = new Intent(this, Menu.class);
startActivity(t);
Your code pick view.Menu.
you have to use :-
Intent t = new Intent(this, com.interviewme.Menu.class);// where menu class here
startActivity(t);
Upvotes: 0
Reputation: 1444
its picking android default Menu
remove this line
import android.view.Menu;
and import your class or change your class name Menu to another name(eg. Menu1)
Upvotes: 2
Reputation: 43821
You imported android.view.Menu
. Try writing out com.interviewme.Menu
instead. Also use better names for your activities. Menu is kind of ambiguous.
Upvotes: 0