I am trying to close the Activity from menu option. When menuItem menu_close_activity
is selected, (and while debugging) I noticed that debugger always jumps from r
I don't see the reason why you activity is not finishing. It should. Could you add some logs to onDestroy()
method and see it's getting called.
As to why the Debugger
is Jumping, well, don't trust the debugger in this case. I think it jumps because of different stuff happening in different threads. Instead add some logs to see what actually happens. Replace your code with the following and check the logs.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_xxxx:
break;
case R.id.menu_yyyy:
break;
case R.id.close_activiy:
// doing some stuff here;
Log.d("DEBUG","BEFORE FINISH = "+item.toString());
setResult(1);
finish(); // Compiler jumps from here
Log.d("DEBUG","AFTER FINISH = "+item.toString());
return true;
default:
Log.d("DEBUG","DEFAULT STATEMENT = "+item.toString());
return super.onOptionsItemSelected(item); // Compiler jumps to here.
}
}