标签: parceler

使用带有Kotlin数据类的Parceler和用于序列化的构造函数

有没有办法使用Parceler与Kotlin数据类和构造函数进行序列化而不使用@ParcelProperty每个字段的注释?

如果我尝试使用这样的库:

@Parcel
data class Valve @ParcelConstructor constructor(val size: Int)
Run Code Online (Sandbox Code Playgroud)

我得到Error:Parceler: No corresponding property found for constructor parameter arg0.但如果我添加@ParcelProperty("size")它就可以了.
这是为什么?

更新:
还有其他方法可以使用此库.
我可以删除@ParcelConstructor注释,但后来我会得到错误
Error:Parceler: No @ParcelConstructor annotated constructor and no default empty bean constructor found.
我认为(没有测试过)我也可以使所有构造函数参数可选并添加@JvmOverloads但是有副作用,我必须检查类的所有属性,如果它们是是否为空.

更新2:
这对我有用:

@Parcel
data class Valve(val size: Int? = null)
Run Code Online (Sandbox Code Playgroud)

简而言之,生成的Java类必须具有默认的空构造函数.实现这一目标的一种方法是如上所述 - 所有变量都应该具有默认值.

parcelable kotlin parceler

23
推荐指数
3
解决办法
8729
查看次数

Gradle 2.3.0-alpha1无法使用数据绑定

今天更新到Android Studo 2.3 Canary后我遇到了问题.

构建完成没有错误但是当我运行应用程序时,gradle控制台一直显示:

找不到android.databinding.annotationprocessor.ProcessDataBinding

这是我的 build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle 2.3.0-alpha1'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.android.databinding:dataBinder:1.0-rc1'
        classpath 'me.tatarka:gradle-retrolambda:3.3.1'
        classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) { …
Run Code Online (Sandbox Code Playgroud)

android build.gradle android-gradle-plugin parceler android-databinding

17
推荐指数
2
解决办法
2329
查看次数

在Android中使用带有Parceler的CLEAN架构

我正在使用CLEAN架构中的项目,其中项目被分解为"Presentation","Domain"和"Data"模块,其中Domain模块托管"实体",这些实体基本上是特定于此的数据模型项目.这种架构的一个例子就在这里.

与其他两个模块不同,"Domain"是一个纯Java库模块,它非常清晰和测试,因为它没有Android开销,但它也意味着我现在无法使用像"Parceler"这样的库这是非常Android特定的.有没有解决的办法?

architecture android parceler

8
推荐指数
1
解决办法
506
查看次数

DP5 7.0 - 为待处理的意图添加额外功能会失败吗?

在跟踪器上添加关联问题:https://code.google.com/p/android/issues/detail? id = 216581 & thanks = 216581 & ts = 1468962325

所以我今天在我的Nexus 5X上安装了DP5 Android 7.0版本.我一直在开发一个应用程序,它使用Android的AlarmManager类在特定时间安排本地通知.在此版本发布之前,代码在运行KitKat,Lollipop和Marshmallow的设备上运行良好.

以下是我如何安排警报:

Intent intent = new Intent(context, AlarmManagerUtil.class);
            intent.setAction(AlarmManagerUtil.SET_NOTIFICATION_INTENT);
            intent.putExtra(AlarmManagerUtil.REMINDER_EXTRA, Parcels.wrap(reminders));
            intent.putExtra("time", when.getMillis());
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            if (alarmManager != null) {
                if (Build.VERSION.SDK_INT >= 23) {
                  alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
                } else if (Build.VERSION.SDK_INT >= 19) {
                    alarmManager.setExact(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
                } else {
                    alarmManager.set(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
                }
Run Code Online (Sandbox Code Playgroud)

我的AlarmManagerUtil @onReceive的"SET_NOTIFICATION_INTENT"如下所示:

public void fireNotification(Context context, Intent intent) {
    List<Reminder> reminderToFire = …
Run Code Online (Sandbox Code Playgroud)

android alarmmanager android-notifications parceler android-7.0-nougat

8
推荐指数
1
解决办法
1133
查看次数

使用Parceler与android

我正在尝试用于Android的Parceler库.到目前为止,我只有一个相同的错误,使用文档中的普通样本.

@Parcel(Parcel.Serialization.BEAN)
public class Example {
  private String name;
  private int age;

  public String getName() { return name; }
  public void setName(String name) { this.name = name; }

  public int getAge() { return age; }
  public void setAge(int age) { this.age = age; }
}
Run Code Online (Sandbox Code Playgroud)

Parcelable p = Parcels.wrap(new Example());
Run Code Online (Sandbox Code Playgroud)

哪个崩溃了

07-30 12:31:46.439: E/AndroidRuntime(4945): FATAL EXCEPTION: main
07-30 12:31:46.439: E/AndroidRuntime(4945): Process: com.sample.app.android.debug, PID: 4945
07-30 12:31:46.439: E/AndroidRuntime(4945):  org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable  class for com.sample.app.android.entity.Example, verify …
Run Code Online (Sandbox Code Playgroud)

android parceler

6
推荐指数
1
解决办法
5859
查看次数

不允许覆盖“writeToParcel”。改用“Parceler”伴随对象

我使用 Jetbrains插件在 Kotlin 中生成 Android Parcelable 类,并得到了这两个异常(不是警告,不像这里,所以项目没有构建):

CREATOR_DEFINITION_IS_NOT_ALLOWED:不允许定义“CREATOR”。改用“Parceler”伴随对象。

OVERRIDING_WRITE_TO_PARCEL_IS_NOT_ALLOWED:不允许覆盖“writeToParcel”。改用“Parceler”伴随对象。

我查看了类似的问题,但没有找到适合我的案例的任何解决方案。

我的 Kotlin 版本:1.1.51(根据 Gradle),但是这个功能是在 1.1.4 中添加的:https ://blog.jetbrains.com/kotlin/2017/08/kotlin-1-1-4-is-out /

自动生成的代码:

@Parcelize
data class User(
        val id: Int,
        val cardId: String,
        val coefficent: Float = 1.0F,
        val name: String,
        val surname: String = ""
) : Parcelable {
    constructor(source: Parcel) : this(
            source.readInt(),
            source.readString(),
            source.readFloat(),
            source.readString(),
            source.readString()
    )

    companion object {
        @JvmField
        val CREATOR: Parcelable.Creator<User> = object : Parcelable.Creator<User> {
            override fun createFromParcel(source: Parcel): User = User(source) …
Run Code Online (Sandbox Code Playgroud)

android parcelable kotlin parceler

6
推荐指数
1
解决办法
2062
查看次数

使用MVP在android中传递bundle意图

我想通过Bundle intent使用Parceler将Model数据传递给另一个活动.我的问题是如何将数据从Presenter传递到View层,以便在Android中使用MVP架构显示另一个活动?

mvp android bundle android-intent parceler

5
推荐指数
1
解决办法
3778
查看次数

使用parceler(@Parcel)和Realm.io(Android)

我有以下代码产生错误: Error:Parceler: Unable to find read/write generator for type io.realm.Realm for io.realm.RealmObject.realm

它没有工作extends RealmObject,但是我想使用Realm轻松地放入数据库.有没有办法驱逐RealmObject字段,只使用@Parcel的基本pojo字段?

@Parcel
public class Feed extends RealmObject{
    int id;
    public String text;
    public String time_created;
    String time_modified;
    int comments_count;
    int likes_count;
    String feed_type;
    int obj_id;
    String image;
    String user_name;
    String user_earthmile_points;
    boolean liked;
    boolean commented;
    boolean is_private;
    String url;
    int feed_creator_id;

   }
Run Code Online (Sandbox Code Playgroud)

android serializable realm parcelable parceler

4
推荐指数
1
解决办法
2784
查看次数

Parceler - 无法找到生成的 Parcelable 类

编辑

清理并重建后,不会生成类


我在尝试使用时遇到此错误Parcels.wrap()

Unable to find generated Parcelable class for xyz.xyz.models.reclamation.Reclamation, verify that your class is configured properly and that the Parcelable class xyz.xyz.models.reclamation.Reclamation$$Parcelable is generated by Parceler.
Run Code Online (Sandbox Code Playgroud)

但是Reclamation$$Parcelable类已经创建了,我可以看到它的内容。

那是我的等级:

compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'
Run Code Online (Sandbox Code Playgroud)

尝试更改annotationProcessorapt导致构建错误。

这就是复垦班

@Parcel
public class Reclamation {

public Reclamation() {
}

private int reclamationProductID;

private Integer preference;

private String takingDate1;

private String takingDate2;

private int takingAddressID;

private String takingAddressStreet;

private String takingAddressCity;

private String takingAddressZipCode;

private int type;

private …
Run Code Online (Sandbox Code Playgroud)

android parceler

4
推荐指数
1
解决办法
3749
查看次数

Parceler:无法找到ForeignCollection类型的读/写生成器

我尝试使用Parceler来使用ORMLite,但Parceler会收到错误:

Error:(44, 36) error: Parceler: Unable to find read/write generator for type com.j256.ormlite.dao.ForeignCollection<PassKeyItem> for CategoryItem.passKeyItems
Run Code Online (Sandbox Code Playgroud)

这是我的对象:

CategoryItem.class

@Parcel
@DatabaseTable(tableName = "categories")
public class CategoryItem {
     ...
    @ForeignCollectionField(columnName = FIELD_PASS_KEY_ITEMS)
    ForeignCollection<PassKeyItem> passKeyItems;
}
Run Code Online (Sandbox Code Playgroud)

PassKeyItem.class

@Parcel
@DatabaseTable(tableName = "passkey")
public class PassKeyItem {
...
  @DatabaseField(foreign = true, foreignAutoRefresh = true, columnName = FIELD_CATEGORY_ITEM_ID)
    private CategoryItem categoryItem;
}
Run Code Online (Sandbox Code Playgroud)

java android ormlite parceler

3
推荐指数
1
解决办法
3508
查看次数