重新启动应用程序后,无法弄清楚如何重新打开标记。

时间:2017-04-12 16:50:01

标签: java android google-maps sharedpreferences

这个项目是创建一个园林导航应用程序。我使用谷歌地图并实施了一个longClick,打开一个意图,从另一个类中添加他们选择的标题和片段的额外信息。

    mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
        @Override
        public void onMapLongClick(LatLng latLng) {
            Intent edit = new Intent(MapsActivity.this, EditActivity.class);
            edit.putExtra("location", latLng);
            MapsActivity.this.startActivityForResult(edit, EDIT_REQUEST);
        }
    });

调用的类看起来像这样: -

    public class EditActivity extends AppCompatActivity {
  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit);


    final LatLng latlng = (LatLng) getIntent().getParcelableExtra("location");

    final EditText title = (EditText) findViewById(R.id.title);
    final EditText snippet = (EditText) findViewById(R.id.snippet);
    Button botton = (Button) findViewById(R.id.save);
    botton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            MarkerOptions marker = new MarkerOptions().position(latlng);

            if (title.getText() != null) {
                marker.title(title.getText().toString());
                marker.snippet(snippet.getText().toString());
            }

            Intent resultIntent = new Intent();
            resultIntent.putExtra("marker", marker);
            setResult(Activity.RESULT_OK, resultIntent);
            finish();
        }
    });
}

}

我是Java开发的新手,并且已经通过指南完成了大部分项目,并进行了大量的Google搜索。我的下一个问题是能够关闭应用程序并使用自定义标记打开它,片段和标题仍然存在吗?如果有人愿意帮助我完成这项工作,请将其与我的代码相关联,这将是非常棒的,请提前感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用Sqlite或SharedPreferences在onPause,onStop或onDestroy方法中存储所需的数据,并在onCreate或onResume上检索它。

Here是一个SharedPreferences教程。