1

I have a GridView where each cell is a thumbnail, a filename and a checkbox. To populate the grid I use a CustomCursorAdapter: The CustomCursorAdapter extends CursorAdapter.

I have a floating button that launchs the system camera. If I take a picture, the grid updates correctly with the new cell.

In the action bar I have a delete button. If I check one or more checkboxes and press the delete button the cell is/are correctly deleted.

But then I have also a ShareActionProvider button so you can check multiple cells and share them. And that works. BUT, here comes the problem. Imagine we have 3 or 4 cells. You check a couple of them, share them, and when you come back from the sharing dialog you see all the cells and you can see how all of them fade and disappear but one, the upper leftmost one.

I checked and saw that after the sharing dialog is the onResume method the one executed. The only thing I'm interested to be done in that method is to reset the checkboxes (a selected.clear() of the variable and a cb.setChecked(false) of each Checkbox view). Also I set the intent of the ShareActionProvider button for a empty selection (this will trigger a Toast: "Select first the images to share" if the button is pressed now).

@Override
  public void onResume() {
      if (shared) { //we come from a share
        uncheck(); //unchecks the Checkboxes views
        selected.clear(); //reset the selected items list

        //getShareIntent returns an intent with the items in 
        //selected (now empty) as extras
        Intent intent = this.getShareIntent();
        if (intent != null && mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(Intent.createChooser(intent,                      
               getResources().getText(R.string.send_to)));
        }
        shared = false;
    }
    super.onResume();
}

Removing the unchecking, reset and new intent setting don't affect to that behaviour, the cells disappear anyway. In fact, if I comment the whole onResume function the problem remains.

I tried with things like:

 grid.invalidateViews();
 mAdapter.notifyDataSetChanged();
 grid.setAdapter(mAdapter);

Also tried and put the super as the first line, but then checkboxes, intent and list variable aren't updated.

Another clue is that if I press the thumbnail of the unique cell left visible (this loads a new activity to see the picture big size), then the disappeared cells appear for a second while the new activity is loading. o_O

I tried to press the places where the thumbnails should appear after the share to check if it launches the big display activity anyway, but that doesn't happen.

I read about similar things when scrolling GridViews but I just have three elements, no need to scroll. What could be happening here?

EDIT: To check if the issue was related to the memory and the thumbnails, I commented them in the item views, letting just the textview and the checkbox. But the problem is still there. Absolutely desperate -I've been days trying to fix this-I tried to relaunch the grid activity in the onResume, to try to force the redraw (while mAdapter.notifyDataSetChanged() worked when adding a new cell, never worked after the sharing):

@Override
public void onResume() {    
    super.onResume();
    if (shared) {
        shared = false;
        Intent intClearStack = new Intent(
                getBaseContext(),
                GridActivity.class);
        intClearStack
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intClearStack);
        finish();
    }t
}

I'm not proud of this solution but is the nearest thing I found to fix this. Nearest because, while it works almost all the time, ocasionally it doesn't. I'd like to know why there's a difference when it comes back from a ShareActionProvider activity and any other activity, to try to find out why this is acting like that.

08Dc91wk
  • 4,254
  • 8
  • 34
  • 67

0 Answers0