Android: Start Activity From Options Menu
I am trying to start an activity from an options menu, but my app keeps crashing. The only error that I receive is an ActivityThread.performLaunchActivity(ActivityThread$ActivityRe
Solution 1:
Intent you are activating should point to some target component, which is not in your case, instead you should do following:
@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
this.closeOptionsMenu();
Intentintent=newIntent(ActivityA.this, ColourActivity.class);
/*Here ActivityA is current Activity and ColourActivity is the target Activity.*/
startActivity(intent);
returntrue;
}
Solution 2:
Try with this,
@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
MenuInflaterinflator= getMenuInflater();
inflator.inflate(R.menu.changescheme, menu);
returntrue;
}
@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
switch(item.getItemId())
{
case R.id.changeScheme:
Log.d("ChangeScheme", "Selected : ChangeScheme Option");
startActivity(newIntent(MainAcitivity.this, ColourActivity.class));
returntrue;
caseR.id.help:
Log.d("HelpMenu", "Selected : Help Option");
//Here put your codereturntrue;
}
}
Solution 3:
Check this:
@OverridepublicbooleanonCreateOptionsMenu(Menu menu){
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.changescheme, menu);
returntrue;
}
@OverridepublicbooleanonOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.changeScheme:
//start activity herebreak;
case R.id.help:
//start activity herebreak;
}
returntrue;
}
Solution 4:
Hi adam your code seem to be perfectly fine while i am testing on my emulator, please check whether you have added the class name "ColourActivity" to your manifest file.
<activityandroid:name="ColourActivity"></activity>
Solution 5:
I have solved the problem now.
It turns out the problem was not at all on the ListActivity
class, it was in fact on the ColourActivity
class.
I was attempting to parse a few colours in onCreate
, but I had forgotten to include the # in one of the RGB colour strings, hence the crash!
Thanks heaps for everyone's help, Adam.
Post a Comment for "Android: Start Activity From Options Menu"