[英]Can't figure out how to have my markers re-open once the application has been restarted.
这个项目是创建一个园林导航应用程序。 我使用谷歌地图,并实施了一个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搜索完成了大部分项目。 我的下一个问题是能够关闭应用程序并使用自定义标记打开它,片段和标题仍然存在吗? 如果有人愿意帮助我完成这项工作,请将其与我的代码相关联,这将是非常棒的,请提前感谢。
您可以使用Sqlite或SharedPreferences在onPause,onStop或onDestroy方法中存储所需的数据,并在onCreate或onResume上检索它。
这是一个SharedPreferences教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.