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() {
super.onPause();
character_dbms.CloseDatabase();
character_dbms = null;
}
protected void onResume() {
super.onResume();
if(character_dbms == null)
{
character_dbms = new CharacterDBMS(this);
}
radio_group.setOnCheckedChangeListener(new RadioGroupListener());
character_selection_listener = new GridViewItemListener();
charactergrid.setOnItemClickListener(character_selection_listener);
}
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());
startActivity(hi);
}
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.
onCreate()
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.lessons);
// LinearLayout
radio_holder = (LinearLayout)this.findViewById(R.id.linearLayout2);
//RadioGroup
radio_listener = new RadioGroupListener();
radio_group = new RadioGroup(this);
radio_group.setOnCheckedChangeListener(radio_listener);
radio_holder.addView(radio_group);
charactergrid = (GridView)findViewById(R.id.gridView1);
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));
radio_buttons[iter].setId(iter);
radio_buttons[iter].setTextColor(R.color.Black);
radio_group.addView(radio_buttons[iter]);
}
String first_lesson_name = character_dbms.GetLessonName(1);
charactergrid.setOnItemClickListener(character_selection_listener);
}
It seems like this block of code should be in your
onCreate()method. TheActivityis still alive in the background afteronResume()is called, so you shouldn’t need to reset the click listeners here.Also, this might simply be dead code, but you never use the
arg1variable inonPause().