I have options menu that opens successfully with icon, but, when I click on it, it does nothing, and also there is nothing in neither LogCat nor error log. Here is my main activity and email activty. I have all buttons in email.xml
and one item in gameoptions.xml
. Please help.
private ListView lv1;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.gameoptions, menu);
menu.findItem(R.id.btn_market);
return true;}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.btn_market:
startActivity(new Intent(getApplicationContext(),EmailActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
email activity:
public class EmailActivity extends Activity {
Button send;
EditText address, subject, emailtext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.email);
Button b=(Button)this.findViewById(R.id.btn_market);
b.setOnClickListener(new OnClickListener(){
public void onClick(View arg0){
Uri address=Uri.parse("https://play.google.com/store/apps/details?id=ru.kenzhekul.tashiev&hl=ru");
Intent surf=new Intent(Intent.ACTION_VIEW, address);
startActivity(surf);
}
});
send = (Button) findViewById(R.id.emailsendbutton);
address = (EditText) findViewById(R.id.emailaddress);
//subject = (EditText) findViewById(R.id.emailsubject);
emailtext = (EditText) findViewById(R.id.emailtext);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { address.getText().toString() });
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,emailtext.getText().toString());
EmailActivity.this.startActivity(Intent.createChooser(emailIntent, "Отправка письма"));
}
});
}
}
The line
startActivity(new Intent(getApplicationContext(),EmailActivity.class));
is wrong.You cannot start an activity with application context as you wrote. You should pass an activity instance instead of the application context.
EDIT: If you are in a class of an activity, try pass
this
instead.