Android onResume displays black screen sometimes, other times it doesn't detect user interaction

Go To


In our Android app, I have an activity that has a gridview that displays bitmaps. When one is clicked on, it calls my custom implementation of AdapterView.OnItemClickListener, where it creates a new intent and calls startActivity(intent). Once I get into the new activity and press the back button, the application either displays the screen of the previous Activity but there is no interacting with it at all, or if it takes a little while to go back to the previous activity (due to breakpoints), then it only shows a black screen. Here is some source from the Activity that eventually launches the new one.

protected void onPause() {
    character_dbms = null;

protected void onResume() {
if(character_dbms == null)
    character_dbms = new CharacterDBMS(this);
radio_group.setOnCheckedChangeListener(new RadioGroupListener());
character_selection_listener = new GridViewItemListener();


Here is the override of the function that launches the new activity

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub
    LinearLayout selectedview = (LinearLayout)arg1;
    Intent hi = new Intent(LessonActivity.this, WhiteboardActivity.class);
    MandarinCharacter temp = (MandarinCharacter)adapter.getItem(arg2);

    hi.putExtra("CharacterID", temp.GetID());

There is nothing special going on the the launched activity, just initializes variables. If you need anymore information or source, please ask, as I am happy to provide it.


public void onCreate(Bundle savedInstanceState){
   // LinearLayout 
      radio_holder = (LinearLayout)this.findViewById(;
      radio_listener = new RadioGroupListener();
      radio_group = new RadioGroup(this);

      charactergrid = (GridView)findViewById(;
      character_selection_listener = new GridViewItemListener();

      character_dbms = new CharacterDBMS(this.getApplicationContext());

      int numberoflessons = character_dbms.GetNumberOfLessons();

      radio_buttons = new RadioButton[numberoflessons];
      for(int iter = 0; iter < numberoflessons; iter++)
          radio_buttons[iter] = new RadioButton(this);
          radio_buttons[iter].setText(character_dbms.GetLessonName(iter + 1));
      String first_lesson_name = character_dbms.GetLessonName(1);

2012-04-04 00:20
by contrapsych
What happens if you comment out the two lines in onPause() which close the database and set the reference to null - Squonk 2012-04-04 00:29
@MisterSquonk Still have the problem. I have that there because I use the database in the other activity, but commenting it out doesn't cause database errors, so I guess those lines are useless - contrapsych 2012-04-04 00:45
OK, it was worth a try just based on a hunch that maybe closing the database was invalidating any Cursor you might have open. As for the lines being useless? Purists will tell you to always close DBs when you're no longer using them but I rarely do it - you can have multiple open 'handles' on an Android SQLite DB without problems - Squonk 2012-04-04 00:55
@MisterSquonk I will go ahead and edit and insert my onCreate, as maybe that will help too - contrapsych 2012-04-04 00:58


It seems like this block of code should be in your onCreate() method. The Activity is still alive in the background after onResume() is called, so you shouldn't need to reset the click listeners here.

radio_group.setOnCheckedChangeListener(new RadioGroupListener());
character_selection_listener = new GridViewItemListener();

Also, this might simply be dead code, but you never use the arg1 variable in onPause().

2012-04-04 00:29
by Alex Lockwood
I deleted the listeners from onResume(), but this problem still exists. I do set the listener in onCreate() BTW, even before. I also get no exceptions, or warning or errors in logcat - contrapsych 2012-04-04 00:40
i suggest using Log.v() to further investigate what is causing your Activity to load incorrectly (i.e. the black screen aspect of your problem should definitely not happen... - Alex Lockwood 2012-04-04 01:10