0

所以我有我的主要活动,它拥有一个列表视图,并有一个地图,其中包含我的所有列表数据。单击项目后,您将进入详细信息显示。当我按下后退按钮从详细活动返回主活动时,如果我设置了一个断点,我的地图键仍然完好无损,但对象中的所有字符串都是“”,整数是-1。这是我的主要活动的样子:

public class MainActivity extends Activity {
    private Map<String, Stunt> stunts = new LinkedHashMap<String, Stunt>();
    private StuntsDao stuntsDao;
    private ListAdapter listAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        stuntsDao = new StuntsDao(getApplicationContext());     

        stunts = stuntsDao.getAllStunts();

        listAdapter = new ListAdapter(this, R.layout.list_layout, new ArrayList<Stunt>(stunts.values()));
        ListView listView = (ListView)findViewById(R.id.listView);

        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                String stuntName = (String)((ViewHolder)view.getTag()).stuntName.getText();
                Intent myIntent = new Intent(getApplicationContext(), StuntDetails.class);
                getStuntDetailsIfNeeded(stuntName);
                Stunt stunt = stunts.get(stuntName);
                myIntent.putExtra("STUNT", stunt);
                startActivity(myIntent);
            }
        });
    }
...

}

为什么我的地图中的对象基本上是空的?

4

1 回答 1

1

单击返回时不会调用 onCreate() 。您需要在 onStart 或 onResume 中再次初始化数据。请参阅:http: //developer.android.com/training/basics/activity-lifecycle/starting.html

于 2013-08-06T15:19:45.580 回答