using android 2.3.3 and Android API 25.
having 3 activities activity_main
, activity_details
and activity_settings
.
I've used android studio auto generating for creating these activities as blank activity with fragment, So manifest code is generated automatically.
activity_main
and activity_details
have menu option Settings
that's for opening the activity_settings
.
clicking on Settings
option menu for activity_details
works and opens activity_settings
but not working for activity_main
and here is my code:
MainActivityFragment.java and DetailActivityFragment.java (same)
`@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) {
startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
}
}`
menu_detail.xml
`<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.poula.sunshine.DetailActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="Settings"
app:showAsAction="never" />
</menu>`
menu_main.xml
`<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.poula.sunshine.MainActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="Settings"
app:showAsAction="never" />
</menu>`