• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Change Activity via Options Menu

gorjan

Lurker
Oct 27, 2010
3
0
Hi All,

I'm really new to Android development, so I have one basic question.
I have the following code. I want to change the screen(the Activity) via Options menu:
Code:
@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId())
		{
		case R.id.item01:
			Intent intentItem1 = new Intent(this, Item1Activity.class);
			startActivityForResult(intentItem1, 0);
			//startActivity(intentItem1);
			return true;
			
		default: return super.onOptionsItemSelected(item);
		}
		
	}

But the activity doesn't change and the error message I receive while debugging is that "The resource doesn't exist"

Any ideas?

Thanks in advance.
 
Your code for changing the activity looks solid.

If you receive the error that a resource cannot be found, that means you're accessing a xml resource that just isn't there. In your example, the only line where you access a resource is your
Code:
case R.id.item01:
line. You should check if your menuitem is really spelled that way.

Besides, your compiler should tell you exactly where and what is causing the error, just check the logcat output.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones