简体   繁体   English

使用Intent将RealmQuery对象传递给Activity

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM