如何在Fragment中使用intent.getExtras()?

时间:2016-03-22 23:38:28

标签: android android-fragments android-intent

我的课程从Fragment延伸,我想在其他课程中添加一个参数。 所以,我正在使用此代码来执行此操作。

Intent intent = new Intent(getActivity(), AddContactActivity.class);
Bundle b = new Bundle();
b.putString("numberPhone", phoneNumber);
b.putString("timeStart", startTime);
intent.getExtras(b);
startActivity(intent);

但这显示错误如:

  

错误:类Intent中的方法getExtras无法应用于给定类型;

     

必需:没有参数

     

发现:Bundle

     

原因:实际和正式的参数列表长度不同

1 个答案:

答案 0 :(得分:0)

如果您想在putExtras(Bundle bundle) 中设置数据包,则应使用 -

Intent intent = new Intent(getActivity(), AddContactActivity.class);
Bundle b = new Bundle();
b.putString("numberPhone", phoneNumber);
b.putString("timeStart", startTime);
intent.putExtras(b);
startActivity(intent);

喜欢 -

// ./models/user   
Var UserSchema = mongoose.Schema({
  name: String,
  posts: [{type: mongoose.SchemaTypes.ObjectId, ref:'Post'}]
});

//  ./models/post
var PostSchema = mongoose.Schema({
  title:String,
  post_body: String,
  posted_by: mongoose.SchemaTypes.ObjectId
});
相关问题