Android : Intent not working in android menu bar

on Tuesday, September 16, 2014


I am creating an app where there is a button on the action bar called About. It should link to an activity by the same name through intent method. But its not working.



public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return true;
}

public boolean onOptionItemSelected(MenuItem item){

switch(item.getItemId()){

case R.id.About:
Intent i = new Intent(this, About.class);
startActivity(i);
return true;

default:
return super.onOptionsItemSelected(item);
}


}


this is the java code, declaring the action to do when the user clicks on action bar button.


The XML code that creates the button is as follows:



<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >


<item android:id="@+id/About" android:orderInCategory="100"
android:showAsAction="always"
android:title="About"/>



</menu>


The meny button is being created and it is clickable, but no event is taking place.


0 comments:

Post a Comment