I’ve making an app and I want to launch a new activity from a menu, but ever time I click the menu button, the app crashes. I’ve tried many ways and all of the have failed.
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(getApplication())
.inflate(R.menu.menu, menu);
return(super.onPrepareOptionsMenu(menu));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.Menu1:
Toast.makeText(this, "Coming soon", Toast.LENGTH_SHORT).show();
break;
case R.id.Menu2:
Intent Intent = new Intent(this, About.class);
startActivity(Intent);
}
return(super.onOptionsItemSelected(item));
}
}
Android Manifest
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name=".AndroidRssReader" 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=".About" android:label="@string/app_label"></activity>
My implementation of
onOptionsItemSelected()is slightly different as I am returningtruewhen I have handled the selection myself, rather than always passing to the superclass.Check the documentation
We really need to see the logcat to be sure though