[英]Pass RealmQuery object to Activity using Intent
I have an Activity
that creates a RealmQuery<E>
and I need to pass this query to another Activity
to execute it. 我有一个创建
RealmQuery<E>
的Activity
,我需要将此查询传递给另一个Activity
以执行它。 I can't do this using an Intent
as the object I'm trying to pass is not parcelable. 我无法使用
Intent
进行此操作,因为我要传递的对象不可包裹。 How can this be achieved? 如何做到这一点?
Passing data back and forth Activity
can be achieved with Intent Extra. 可以使用Intent Extra实现来回传递数据
Activity
。
You can simply do the following 您可以简单地执行以下操作
First Activity
Firstly obtain your data into variable its datatype 首次
Activity
首先将数据获取为数据类型的变量
String uid = myModel.getUid();
Sending data to ChefProfile
class 将数据发送到
ChefProfile
类
Intent intent = new Intent(MainActivity.this, ChefProfile.class);
intent.putExtra(ChefProfile.EXTRA_USER_ID, uid);
startActivity(intent);
Now let get the data from Intent since it has arrived to the calling activity 现在让我们从Intent中获取数据,因为它已经到达了调用活动
This is Chef_Profile
class. 这是
Chef_Profile
类。 Firstly, we have to create a constant field for the data arrived. 首先,我们必须为到达的数据创建一个常量字段。
private static final String EXTRA_USER_KEY = "uid";
//Here we obtain the data sent from first activity and extract it into userId
userId = getIntent().getStringExtra(EXTRA_USER_KEY);
if (userId == null) {
throw new IllegalArgumentException("Must pass EXTRA_POST_KEY");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.