Starting New Activity From Onoptionsitemselected
I am trying to start a new activity(Settings Activity) from onOptionsItemSelected, but i am getting fatal exception when i click on option two it starts settings activity for a whi
Solution 1:
Use something like this:
publicbooleanonOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_option_two:
Intentintent=newIntent(this, SettingsActivity.class);
startActivity(intent);
returntrue;
}
returnsuper.onOptionsItemSelected(item);
}
Solution 2:
Caused by: java.lang.NullPointerException
04-1903:59:34.679: E/AndroidRuntime(2733): at com.example.homeautomation.Room1.onStop(Room1.java:183)
Just set a breakpoint
here (Room1.onStop)
and find out what is null.
Solution 3:
While searching the web, I came across this, which is an alternative to what you`re trying to do.
You could have a base activity with 2 buttons( if you like ), one to take you to your main activity and another to take you to settings.
Post a Comment for "Starting New Activity From Onoptionsitemselected"