I have an activity that refuses to close the first time finish() is called. I had originally put a Cancel button in the activity, but then I noticed that it exhibits the same behavior when I use the Back button too. It can be described like this: 1. The activity opens, and the appropriate data is filled in (which came from a List View from the previous activity). 2. Press the Back button, and all the fields are cleared of data, but it doesn't return the user to the original activity. 3. Press the Back button again, and the user is returned to the original activity.
I can post code, but I'm not sure if the issue is in the current activity or the main one. I can mention that switched to using a context menu to open the Activity.
UPDATE: Ok, looks like both of these suggestions were correct, the main activity is indeed launching 2 versions of the Edit activity. Now I'm just trying to figure out why. I noticed this happening when I switched over to a context menu for the list item options. The Add button is a Menu Item, however. Here is the relevant code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// add(int groupId, int itemId, int order, int titleRes)
menu.add(0, INSERT_ID, 0, R.string.menu_insert);
menu.add(0, SETTINGS_ID, 1, R.string.sharedPrefButton);
menu.add(0, COMMON_DESC_ID, 2, R.string.commonDescButton);
menu.add(0, RESET_ID, 3, R.string.menu_reset);
return true;
}
/*
* This is going to handle the "Add Expenditure" menu item. When this is selected, the
* onOptionsItemSelected() method will be called with the item.getId() set to INSERT_ID
* (the constant we used to identify the menu item).
*/
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case INSERT_ID:
createExpenditure();
break;
case SETTINGS_ID:
manageSharedPrefs();
break;
case COMMON_DESC_ID:
manageCommonDesc();
break;
}
return super.onMenuItemSelected(featureId, item);
}
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
menu.add(0, EDIT_ID, 0, R.string.menu_edit);
}
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int itemId = item.getItemId();
switch(itemId) {
case DELETE_ID:
mDbHelper.deleteExpenditure(info.id);
fillData();
break;
case EDIT_ID:
Intent i = new Intent(this, ExpenditureEdit.class);
i.putExtra(ExpendituresDbAdapter.KEY_ROWID, info.id);
startActivityForResult(i, ACTIVITY_EDIT);
break;
}
return super.onContextItemSelected(item);
}