I have several activities in my app. I want my activities to have the same menuitem, except one. I was wondering if there is an easy way to put the menuitem in all selected activities instead of copying and pasting the menuitem for each single activity? Basically I want to share the menuitem with selected activities.
Thanks,
Transitioning Between Activities in AndroidThe SecondActivity will contain a ConstraintLayout with a TextView label showing “Second Activity” and a Button with the text “Back to First Activity”.
Intent i = new Intent(FromActivity. this, ToActivity. class); startActivity(i); In this case the Intent uses your current Activity as the Context in the first parameter, and the destination Activity in the second parameter.
create a class (say class A) which extends activity and then create all your other activities by extending this class. Now in A keep the common menu items stored in a vector and any specific menu action can be added for any particular activity. This way you avoid the trouble of copying and pasting the menu items in every activity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With