Thursday, July 14, 2011

[android-developers] Activity finish() not working properly

Dear Android Community,

I'm having a strage problem and have no idea what might be wrong. I
have an option menu in an Activity, let's call it A, in which one of
the options needs to start a new Activity, B, and close A. The problem
is that the caller activity, B, is not closing. Instead Activity B is
launched, closes and goes back to Activity A. Weird!

Here's a sample of my code...

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case x:
.......//do something
break;
case y:
......//do something else
break;
case z:
Intent intent = new Intent(A.this, B.class);
startActivity(intent);
this.finish();
break;
}
return true;
}

I have tried moving the order in every way possible and some other
workarounds I have found online, but nothing seems to work. I hope
someone has encountered this problem before or has an idea of what
might be wrong. Thanks in advance.

Cheers,
Jalal

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment