I got a problem with a quite large GridView.(about 70 children) The GridView works fine if I start it on onCreate or after resumeing after pressing the home button and then return. But when I resume after coming back from sleep mode, my BaseAdapter starts again and ruin the changes I have done to it during runtime. This also make getChildAt() give a NullPointerException if I am calling it just after restart.

How can I make it just do what regular onPause(home button) does to the GridView, and avoid that the GridView is wiped out everytime I am resumeing from sleep mode?

Edit: I have tried setting a wakelock for my Activity class that calls the BaseAdpter with no luck

2.Edit: Since I posted this question I have played around with trying to restore the GridView using this code in onPause:

 SparseArray<Parcelable> array = new SparseArray<Parcelable>();
    gridView.saveHierarchyState(array);
    bundle = new Bundle();
    bundle.putSparseParcelableArray("state", array);

And this in onResume:

 try{
    gridView.restoreHierarchyState(bundle.getSparseParcelableArray("state"));
    }
    catch(Exception e){
        //Most likely first start
        Log.i("SomeTag", "No GridView state found");
    }

    }

The strange thing is everything I seems to have jumped from one place to another on the screen and it is still crashing when I try to getChildAt(). It is also failing to get it after sleep mode.

  1. Edit Here is the code from BaseAdapter getView(Note! some of this code is irrelevant)

public View getView (int position, View convertView, ViewGroup parent) {

mParentView = parent;


DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;

    //sets the height for every individual box
int box = width/7*6/10;

ImageCell v = null;
if (convertView == nu
Edit
Report