ACTION BAR INTENTS ACTIVITY

Simple steps to put intents in action bar menu.
Step 1:
Create multiple activities.
Step 2:
Set every activity with something to understand when activity is changed.
eg.
Step 3 :
Get this code below and put it into add source directly block  :

}
@Override
public boolean onCreateOptionsMenu(Menu menu){

menu.add("First Activity").setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

menu.add("Second Activity").setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

menu.add("Third Activity").setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

return true;
}

@Override 
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getTitle().toString())
 {
case "First Activity":
Intent a = new Intent (MainActivity.this,MainActivity.class);
startActivity (a);
return true;

case "Second Activity":
Intent b = new Intent (MainActivity.this,SecondActivity.class);
startActivity (b);
return true;

case "Third Activity":
Intent c = new Intent (MainActivity.this,ThirdActivity.class);
startActivity (c);
return true;

default:
return super.onOptionsItemSelected(item);
}
Step 4 :
Set activity's name that you put your code in all as shown below.
Step 5:
Set menu add name of your choice and case :
NB: menu add name and case name must be equal.
Final step :
Set your case activities name.

NB: 
You must add code to every activity and set activity name in intents code and intents must have different name like (a), (b) etc.. As shown in the screen shot.

Comments

Popular posts from this blog

Trust Wallet yadda ake budewa

HANYOYI 8 DA ZA A SAMU DAGA SHIRIN KARFIN SMART CONTRACT