在我们的 Android 应用程序中,我有一个具有显示位图的网格视图的活动。单击一个时,它会调用我的 AdapterView.OnItemClickListener 的自定义实现,它会在其中创建一个新意图并调用 startActivity(intent)。一旦我进入新的活动并按下后退按钮,应用程序要么显示上一个活动的屏幕,但根本没有与之交互,或者如果需要一点时间才能回到上一个活动(由于断点),那么它只显示黑屏。这是最终启动新活动的活动的一些来源。
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);
}
这是启动新活动的函数的覆盖
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);
}
启动的活动没有什么特别的,只是初始化变量。如果您需要更多信息或来源,请询问,因为我很乐意提供。
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);
}