android - 我怎样才能在两个不同的活动中获得这些意图值
问题描述
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
int title = Integer.parseInt(marker.getTitle());
Log.d("Result", String.valueOf(marker));
//pass these value in two diffrent activities to update sqlite database
Intent a = new Intent(MapsActivity.this, Abc.class);
a.putExtra("customer_id", title);
startActivity(a);
}
解决方案
您必须创建两个Intents
才能这样做。
Intent a = new Intent(MapsActivity.this, Abc.class);
a.putExtra("customer_id", title);
startActivity(a);
Intent b = new Intent(MapsActivity.this, <service-name>.class);
b.putExtra("customer_id", title);
startService(b);
在您的 Activity 中,按如下方式访问它:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
int customerId = getIntent().getIntExtra("customer_id", 0);
...
}
在您的服务中按如下方式访问它:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final int customerId = intent.getIntExtra("customer_id",0);
return Service.START_NOT_STICKY;
}
推荐阅读
- javascript - 获取未捕获的类型错误:无法读取 null 的属性“getAttribute”但代码正在运行
- javascript - 选择 ng-options 引发 $digest() 迭代达到错误
- javascript - 当我从选择选项中获得现金价值时如何禁用另一个选择选项
- mongodb - MongoDb:获取复杂数据的总计 $avg
- python - 如果数据帧长度超过阈值,则创建一个新行 python
- html - 如何在 Materialise CSS 中制作 7 列网格?
- angular - 在角度 6 中将背景类应用于父 div
- javascript - Cut and paste data range to bottom of another sheet
- java - 同一程序的 IDE 启动版本和 jar 版本之间的输出不同
- jquery - Jquery blur not working when scrolling the page