天道酬勤,学无止境

parcelable

onSaveInstanceState() vs. onRetainCustomNonConfigurationInstance()

I am using ActionBarSherlock, along with several MenuItems that I dynamically manage, depending on program state. Specifically, I save the MenuItems into instance variables in the Activity's onCreateOptionsMenu() method, and then can show and/or hide them as needed later in the Activity. However, I found that the MenuItem variables can be lost on configuration changes, such as device rotation. So I also put them into a Parcel and pass them to onSaveInstanceState() for restoral through the savedInstanceState mechanism in the next onCreate() call, if needed. This seems to work fine in the case

2021-06-24 08:43:39    分类:问答    android   actionbarsherlock   parcelable   android-optionsmenu   android-configchanges

How to send an object containing drawable objects from one android activity to another using intents?

I've gone through this: How to send an object from one Android Activity to another using Intents? But i'm facing problem in sending images in the object to the other activity. Please help.

2021-06-24 08:31:02    分类:问答    android   android-intent   parcelable

Storing a Parcelable object to a File in Android

I am trying to store an ArrayList of ResolveInfo objects to a file so that I don't have to rebuild it each time my application launches (about 4-6 seconds) ResolveInfo objects are Parcelable, but not Serializable so I get a java.io error when I try to write the objects. I have stored them in my savedInstanceState bundle, but that doesn't help when closing the application. Am I doing something plain wrong?

2021-06-24 06:33:32    分类:问答    android   file   object   bundle   parcelable

How to marshal/unmarshal ContentValues to insert generic type into ContentProvider?

I want to put a generic POJO into ContentValues and unmarshall it within the ContentProvider. I've been wracking my tiny brain re: Parcelables, ContentValues, and inserting into SQLite Regarding: http://njzk2.wordpress.com/2013/05/31/map-to-contentvalues-abusing-parcelable/ How to write a common code for inserting data in android's Sqlite I've been trying to insert a android.location.Location into SQLite via ContentProvider: Location loc = mLocationClient.getLastLocation(); myParcel = android.os.Parcel.obtain(); loc.writeToParcel(myParcel, 0); ContentValues values = ContentValues.CREATOR

2021-06-24 03:30:25    分类:问答    android-contentprovider   parcelable   parcel

com.android.support:appcompat-v7 and design version 23.2.0 崩溃包错误(com.android.support:appcompat-v7 and design version 23.2.0 crash parcel error)

问题 我在我的应用程序中使用了来自 android 支持的几个库,并在它们可用时更新它们。 在 23.2.0 版本的测试期间,当我在 android 6 上更改应用程序权限时发生了崩溃。如您所知,当用户禁用权限时,应用程序会重新创建(与设备旋转时的方式相同)并且您的可打包对象被保存并从一个包中恢复。 在 23.2.0 版本中,当重新创建应用程序时,我遇到了包裹错误。 我认为这个错误不是来自我的代码,而是来自 android 代码。 当我使用 23.1.1 或更低版本的库时,我没有出现此错误。 这是一个转储: E/AndroidRuntime:致命异常:主进程:org.team.acs.scubalog,PID:15378 java.lang.RuntimeException:无法启动活动 ComponentInfo{org.team.acs.scubalog/org.team.acs.scubalog.MainActivity }: java.lang.RuntimeException: Parcel android.os.Parcel@3a99bef: 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread

2021-06-23 18:25:46    分类:技术分享    android   android-support-library   parcelable   parcel

是否可以在 Android 上创建可 Parcelable 的 HashMap?(Is it possible to create a HashMap that is Parcelable on Android?)

问题 我试图将 HashMap 扩展为 Parcelable 并且我得到了编译的语法,但是,在运行时它抛出一个异常并返回一个空指针试图解组数据。 发送方必须强制转换为 (Parcelable) 以解决歧义,但是,接收方抱怨预期 Parcelable 但找到了 HashMap。 有没有人成功过这个? 我的语法错了吗? 有更好的解决方案吗? 以下是代码: HomeActivity.java - 发件人 ContentViewActivity.java - 接收器 ContentItemSimple.java - 顾名思义(包装一个字符串和整数) ContentItemCollection.java - 这是 HashMap 家庭活动.java package com.mobibob.android.studyparceable; import java.util.HashMap; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.text.format.Time; import android.util.Log; import

2021-06-23 16:48:23    分类:技术分享    android   hashmap   parcelable

将 Parceler 与 Kotlin 数据类与构造函数一起用于序列化(Use of Parceler with Kotlin data class with constructor for serialization)

问题 有没有办法将 Parceler 与 Kotlin 数据类和构造函数一起使用来进行序列化,而无需为每个字段使用@ParcelProperty批注? 如果我尝试使用这样的库: @Parcel data class Valve @ParcelConstructor constructor(val size: Int) 我得到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可选并添加@JvmOverloads但这有一个副作用,即我必须检查类的所有属性是否为空。 更新2 : 这对我有用: @Parcel data class Valve(val size: Int? = null) 简而言之,生成的

2021-06-23 04:50:09    分类:技术分享    parcelable   kotlin   parceler

How to pass object which contain Bitmap to another activity

so I am kind of new in Android Developing, I was trying to make a Sign-up Activity (UserPrivateInfoSignUpActivity.java) that load a picture (Bitmap) and create a UserPersona Object that I want to pass into another Activity (UserGeneralDataSignUpActivity). I did a research for solutions and somehow I am still unable to pass the Bitmap image although it is already implements Parcelable. Any suggestions? Here is my code (without getters & setters) PersonaUser.java: public class PersonaUser implements Parcelable{ private String puName; private String puEmailAddress; private String puCountry

2021-06-22 15:51:13    分类:问答    java   android   android-activity   bitmap   parcelable

Can Nulls be passed to parcel?

Is it possible to write null to Parcel when parcelling an object, and get null back again when unparcelling it again? Let's assume we have the following code: public class Test implements Parcelable { private String string = null; public Test(Parcel dest, int flags) { source.writeString(string); } } Will I get a NullPointerException when reading this value back from the parcel using Parcel.readString()? Or will I get a null value out?

2021-06-22 04:24:39    分类:问答    android   parcelable   parcel

在 Handler 消息中放入一个对象(Put an object in Handler message)

问题 我需要在不同的线程中从互联网下载图像, 然后将处理程序消息中的图像对象发送到 UI 线程。 我已经有了这个: ... Message msg = Message.obtain(); Bundle b = new Bundle(); b.putParcelable("MyObject", (Parcelable) object); msg.setData(b); handler.sendMessage(msg); 当我收到此消息时,我想提取对象: ... public void handleMessage(Message msg) { super.handleMessage(msg); MyObject objectRcvd = (MyObject) msg.getData().getParcelable("IpTile"); addToCache(ipTile); mapView.invalidate(); } 但这给了我: ...java.lang.ClassCastException... 任何人都可以帮忙吗? 顺便说一句,这是最有效的方式吗将对象传递给 UI 线程? 谢谢你们! 回答1 我会使用 AsyncTask 进行这种操作。 它允许您连接到您的 ui 线程以进行诸如进度更新之类的事情,并且一旦您完成下载。 下面的例子展示了一个人应该如何做: class

2021-06-21 22:54:28    分类:技术分享    android   handler   parcelable