gpt4 book ai didi

java - 无法弄清楚如何在应用程序重新启动后重新打开我的标记。

转载 作者:太空宇宙 更新时间:2023-11-04 11:35:15 26 4
gpt4 key购买 nike

这个项目是创建一个花园导航应用程序。我使用谷歌地图并实现了一个 longClick,它打开一个 Intent ,将来自另一个类的额外信息以及他们选择的标题和 fragment 放入其中。

    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 开发确实很陌生,并且通过指南和大量谷歌搜索完成了这个项目的大部分内容。我的下一个问题是能够关闭应用程序并使用自定义标记打开它,并且代码 fragment 和标题仍然存在?如果有人愿意引导我将其与我的代码联系起来,那就太棒了,提前致谢。

最佳答案

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

Here是一个 SharedPreferences 教程。

关于java - 无法弄清楚如何在应用程序重新启动后重新打开我的标记。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43375360/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com