Unable To Finish Activity From Onoptionsitemselected In Android
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 return true step
Solution 1:
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.
@OverridepublicbooleanonOptionsItemSelected(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());
returntrue;
default:
Log.d("DEBUG","DEFAULT STATEMENT = "+item.toString());
returnsuper.onOptionsItemSelected(item); // Compiler jumps to here.
}
}
Post a Comment for "Unable To Finish Activity From Onoptionsitemselected In Android"