android - 如何通过意图提供数据重新加载相同的活动?
问题描述
以下是我的代码,但在重新加载活动后我没有得到restaurant_id
;
Intent refresh = new Intent(getApplicationContext(), RestaurantDetailActivity.class);
refresh.putExtra("restaurant_id", mDataset.get(position).getRestaurantId());
startActivity(refresh);
finish();
解决方案
请尝试以下步骤...
刷新
RestaurantDetailActivity
Intent intent = new Intent(RestaurantDetailActivity.this, RestaurantDetailActivity.class); Bundle bundle = new Bundle(); bundle.putInt("restaurant_id", mDataset.get(position).getRestaurantId()); intent.putExtras(bundle); startActivity(intent); RestaurantDetailActivity.this.finish();
在
OnCreate()
你应该在同一个活动中这样做if(getIntent().getExtras() != null) { Bundle extras = getIntent().getExtras(); int restaurantId = extras.getInt("restaurant_id"); // todo with restaurantId }
推荐阅读
- elasticsearch - 如何在弹性搜索中使用必须和应该
- python - 比较重叠的数组列表
- javascript - 在 Web Audio API 中,有没有办法设置最大音量?
- python - 如何在有条件地排除某些字符串和数字的情况下计算列表的长度?Python
- javascript - 当我的函数似乎返回正确答案时,为什么 console.log() 未定义日志记录?
- list - 在 Haskell 中对列表进行三角化
- javascript - 在我添加箭头函数来调用我正在使用的函数后,onClick 事件不起作用
- javascript - 在 angularjs 中加载后如何将值传递给 html
- reactjs - 在 ReactJS 中选择性显示 JSON 数据
- reactjs - ELIFECYCLE 1 推送到 Heroku 时出错