- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我基本上想做的是将 Parcelable 对象作为 Intent extra 传递。
这是我经过的地方,
final Intent intent = new Intent(_context,
AddReminderActivity.class);
final Bundle bundle = new Bundle();
bundle.putString(AddReminderActivity.EXTRA_MODE, AddReminderActivity.MODE_EDIT);
bundle.putParcelable(AddReminderActivity.EXTRA_REMINDER, _reminders.get(position));
intent.putExtras(bundle);
_context.startActivity(intent);
_reminders
是一个 ArrayList<Reminder>
这是我的 Reminder
类
package au.com.elegantmedia.vetcheck.objects;
import android.os.Parcel;
import android.os.Parcelable;
public class Reminder implements Parcelable {
private long _id;
private String _message = "n/a";
private String _medication = "n/a";
private String _dosage = "n/a";
private String _date = "n/a";
private String _time = "n/a";
private int _repeatID = 0; // 1-once, 2-hourly, 3-daily, 4-weekly, 5-monthly
private String _repeat = "n/a";
private int _requestCode = 0;
private static int REPEAT_ID_ONCE = 1;
private static String REPEAT_ONCE = "once";
private static int REPEAT_ID_HOURLY = 2;
private static String REPEAT_HOURLY = "hourly";
private static int REPEAT_ID_DAILY = 3;
private static String REPEAT_DAILY = "daily";
private static int REPEAT_ID_WEEKLY = 4;
private static String REPEAT_WEEKLY = "weekly";
private static int REPEAT_ID_MONTHLY = 5;
private static String REPEAT_MONTHLY = "monthly";
public Reminder() {
// TODO Auto-generated constructor stub
}
public Reminder(Parcel source) {
_id = source.readInt();
_message = source.readString();
_medication = source.readString();
_dosage = source.readString();
_date = source.readString();
_time = source.readString();
_repeatID = source.readInt();
_repeat = source.readString();
_requestCode = source.readInt();
}
public long getID() {
return _id;
}
public void setID(long id) {
_id = id;
}
public String getMessage() {
return _message;
}
public void setMessage(String message) {
if(!message.equals("")) {
_message = message;
}
}
public String getMedication() {
return _medication;
}
public void setMedication(String medication) {
if(!medication.equals("")) {
_medication = medication;
}
}
public String getDosage() {
return _dosage;
}
public void setDosage(String dosage) {
if(!dosage.equals("")) {
_dosage = dosage;
}
}
public String getDate() {
return _date;
}
public void setDate(String date) {
if(!date.equals("")) {
_date = date;
}
}
public String getTime() {
return _time;
}
public void setTime(String time) {
if(!time.equals("")) {
_time = time;
}
}
public void setRepeatID(String repeat) {
if(repeat.equals(REPEAT_ONCE)) {
_repeatID = REPEAT_ID_ONCE;
}
else if(repeat.equals(REPEAT_HOURLY)) {
_repeatID = REPEAT_ID_HOURLY;
}
else if(repeat.equals(REPEAT_DAILY)) {
_repeatID = REPEAT_ID_DAILY;
}
else if(repeat.equals(REPEAT_WEEKLY)) {
_repeatID = REPEAT_ID_WEEKLY;
}
else if(repeat.equals(REPEAT_MONTHLY)) {
_repeatID = REPEAT_ID_MONTHLY;
}
}
public int getRepeatID() {
return _repeatID;
}
public void setRepeat(int repeatID) {
_repeatID = repeatID;
if(repeatID == REPEAT_ID_ONCE) {
_repeat = REPEAT_ONCE;
}
else if(repeatID == REPEAT_ID_HOURLY) {
_repeat = REPEAT_HOURLY;
}
else if(repeatID == REPEAT_ID_DAILY) {
_repeat = REPEAT_DAILY;
}
else if(repeatID == REPEAT_ID_WEEKLY) {
_repeat = REPEAT_WEEKLY;
}
else if(repeatID == REPEAT_ID_MONTHLY) {
_repeat = REPEAT_MONTHLY;
}
}
public String getRepeat() {
return _repeat;
}
public void setRequestCode(int requestID) {
_requestCode = requestID;
}
public int getRequestCode() {
return _requestCode;
}
// parceling part
public static final Parcelable.Creator<Reminder> CREATOR = new Parcelable.Creator<Reminder>() {
@Override
public Reminder createFromParcel(Parcel source) {
return new Reminder(source);
}
@Override
public Reminder[] newArray(int size) {
return new Reminder[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(_id);
dest.writeString(_message);
dest.writeString(_medication);
dest.writeString(_dosage);
dest.writeString(_date);
dest.writeString(_time);
dest.writeInt(_repeatID);
dest.writeInt(_requestCode);
}
}
我遇到的问题是,当从调用者 Activity 传递包时,它是这样的,
Bundle[{reminder=au.com.elegantmedia.vetcheck.objects.Reminder@41fade98, mode=edit}]
意味着一切都按预期设置,但是当尝试从被调用者 Activity (final Bundle bundle = getIntent().getExtras();
) 访问额外内容时,如下所示,
Bundle[mParcelledData.dataSize=308]
此时我尝试按如下方式访问包,
if(bundle.getString(EXTRA_MODE).equals(MODE_ADD)) {
}
else if(bundle.getString(EXTRA_MODE).equals(MODE_EDIT)) {
final Reminder reminder = getIntent().getParcelableExtra(EXTRA_REMINDER);
populateData(reminder);
}
我遇到了以下异常
E/AndroidRuntime(17991): Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@416ee8b0: Unmarshalling unknown type code 6357102 at offset 172
这是我对 Parcelable 对象的第一次尝试,所以我不太清楚这意味着什么,谷歌搜索了几个小时并没有完全帮助缩小问题范围。
最佳答案
您的 _id
是 long
类型,您将其解码为 int
类型:
_id = source.readInt();
不应该吗
_id = source.readLong();
我还注意到您阅读的顺序与写入包裹的顺序不同。 _repeat
编码时未写入包裹。
关于android - 解码未知类型代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18733924/
我有一个交叉表函数,我过去曾多次成功使用它,但现在它在最后转储所有数据,而不是将其旋转到输出表中。它似乎无法找到交叉表。我通过以下方式对其进行了研究; 如果 tablefunc 不存在则创建扩展; -
表1(客户表) Id, CustomerId, IsKnownCustomer,phonemacaddress 1, 空 0 00:9a:34:cf:a4 2, 004024 1 00:6f:64:c
知道为什么我总是收到这个烦人且无用的错误代码/描述吗? Failed to pull image myapidemodocker.azurecr.io/apidemo:v4.0: rpc error:
我正在进行 PHP 登录,并且之前可以正常工作,但我尝试使用户名功能不区分大小写,但此后代码一直无法正常工作。我删除了我添加的所有内容,以尝试使其不区分大小写,即 strtolower()。页面上显示
有人会帮助我提供有关此错误的任何可能信息吗?原因?登录?在哪里寻找/开始? Cannot use output buffering in output buffering display handl
我已经添加了这样的脚本 我在我的 test.js 中做了这个 var app = angular.module('MyApp', ['ngRoute']).config
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我有这个sql语句: selectAllUsersByCriteria = 连接.prepareStatement( “从用户那里选择*?=?” ); 下面的方法运行该语句: public Array
我有一个白色的 EditText,在 Android 3.1 及更高版本中,光标不显示(因为它也是白色的)。有关信息,我使用 android:background="@android:drawable
我正在尝试使用 Keras 实现深度学习模型。但是我有一个未知形状实现的问题。我一直在寻找类似的错误,但没有找到。 这是我的代码。 Xhome = dataset[:,32:62] Xaway = d
关注此introduction可以通过导入命名空间 System.Xml 来使用 XMLReader 类。在我的 Visual Studio 项目中,我使用 .NET 4.0,但 System.Xml
我有一个动态链接库的程序。该程序将函数指针传递给该库以执行。 但是 ubsan(Undefined Behavior Sanitizer)指定指针位于错误的函数类型上。那只会发生 如果回调函数有一个类
我正在尝试在我的 Swift SpriteKit 应用程序中使用 AVAudioSession。我遇到了奇怪的“未声明类型”问题。例如…… import AVFoundation var audioS
如果在编译期间(在实际编译和运行程序之前)其参数之一的值已知/未知,如何专门化模板函数? 我还不知道怎么做。 想法 1: #include #include int main(void){
我看到一些人的代码是这样的: while (!(baseType == typeof(Object))) { .... baseType = baseType.BaseType;
我正在尝试使用 GoColly 框架获取所有 HREF 链接,但是只允许任何域的 url 为根 URL 或子域(否路径)。我已经注释掉了我的 REGEXP。文件扩展名没有事情。我只是在“/”之后不想要
我有一个包含多个实体的数据库,特别是 Book 和 User。它们之间存在这样的 ManyToMany 关系: 书: @Entity @Table(name = "Books") public cla
如果我将范围的初始部分设置为 Range("A:A"),如何确保将整行传递给排序? 数据 id、fname、mname、lname、后缀、状态、位置、时区 通过在 id 中搜索起点和终点来选择范围。
我对kubernetes很陌生,而对于docker来说就不那么多了。 我一直在研究示例,但是我对自动缩放器(似乎无法缩放)感到困惑。 我在这里通过示例https://kubernetes.io/doc
我在 ChildWindow 中使用 SL Toolkit 5 中的 BusyIndicator 控件。 在某些解决方案中,它可以工作,但在其他解决方案中,使用完全相同的代码(至少看起来),我在运
我是一名优秀的程序员,十分优秀!