Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Click Share icon on action menu shows nothing

Currently I am on end of the blog reader series. There is some problem I faced, my share icon is on the top and I click it nothing happen.

Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, mUrl ); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_chooser_title)));

1 Answer

Are you sure in your "OnOptionsItemSelected" that you are referencing the correct ID for the share button?

public boolean onOptionsItemSelected (MenueItem item){
  switch (item.getItemId()){
    case R.id.menu_action_share:  //<- This should be whatever the ID you gave the button in your menu.xml file
      Intent shareIntent = new Intent(Intent.ACTION_SEND); 
      shareIntent.setType("text/plain"); 
      shareIntent.putExtra(Intent.EXTRA_TEXT, mUrl );
      startActivity(Intent.createChooser(shareIntent, getString(R.string.share_chooser_title)));
      break;
    }
    return true
}