我的应用程序中有一个选项菜单,其中显示了用户在地图上添加的所有标记的列表。标记使用 ListView 表示,当用户选择该 ListView 的一项时,我想返回(恢复?)到主要活动,将标记位置作为参数传递,但不创建新活动。那可能吗?现在,当用户单击任何项目时,我正在创建一个新活动,是否可以简单地回到主要活动?
MarkersList 活动的代码:
mainListView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
{
Intent intent = new Intent(getBaseContext(), MainActivity.class);
MyMarkerObj marker = (MyMarkerObj)table.get(position);
intent.putExtra("position", marker.getId());
startActivity(intent);
finish();
}
});
MainActivity 代码:
@Override
protected void onResume() {
Intent intent = getIntent();
if (intent != null) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
int reportId = bundle.getInt("position");
Toast.makeText(getApplicationContext(), Integer.toString(reportId), Toast.LENGTH_SHORT).show();
try {
data.open();
} catch (Exception e) {
Log.i("hello", "hello");
}
//Get the marker selected in the listview
String position = data.getMarkerById(reportId);
//System.out.println(">>>>>>>>>>>>>>> position = " + position);
}
}
super.onResume();
}