Adding a RealmObject to a RealmList in Android - android

I am currently trying to add a RealmObject to RealmList inside another RealmObject.
So this is the way I am doing it at the moment.
First I create and save a RealmObject called "RouteRealm" like this:
public void insertNewRoute(int routeId, long routeDate) {
realm.beginTransaction();
RouteRealm routeRealm = realm.createObject(RouteRealm.class);
routeRealm.setId(routeId);
routeRealm.setDate(routeDate);
realm.commitTransaction();
}
The class RealmObject looks like this:
public class RouteRealm extends RealmObject {
#PrimaryKey
private int id;
private long date;
private RealmList<RoutePointRealm> routePoints;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public RealmList<RoutePointRealm> getRoutePoints() {
return routePoints;
}
public void setRoutePoints(RealmList<RoutePointRealm> routePoints) {
this.routePoints = routePoints;
}
}
The above works. The problem occurs when I try to add a RoutePointRealm to the list called routePoints. Here is my code for adding the RoutePointRealm object to the list:
public void insertNewRoutePoint(int routeId, String address, float latitude, float longitude, long routePointId, long routePointTime) {
realm.beginTransaction();
RouteRealm routeRealm = realm.where(RouteRealm.class).equalTo("id", routeId).findFirst();
RoutePointRealm routePointRealm = realm.createObject(RoutePointRealm.class);
routePointRealm.setAddress(address);
routePointRealm.setLatitude(latitude);
routePointRealm.setLongitude(longitude);
routePointRealm.setRoutePointID(routePointId);
routePointRealm.setRoutepointTime(routePointTime);
routeRealm.getRoutePoints().add(routePointRealm);
realm.copyToRealmOrUpdate(routeRealm);
realm.commitTransaction();
}
And the RoutePointRealm looks like this:
public class RoutePointRealm extends RealmObject {
#PrimaryKey
private long routePointID;
private float longitude, latitude;
private long routepointTime;
private String address;
public long getRoutePointID() {
return routePointID;
}
public void setRoutePointID(long routePointID) {
this.routePointID = routePointID;
}
public float getLongitude() {
return longitude;
}
public void setLongitude(float longitude) {
this.longitude = longitude;
}
public float getLatitude() {
return latitude;
}
public void setLatitude(float latitude) {
this.latitude = latitude;
}
public long getRoutepointTime() {
return routepointTime;
}
public void setRoutepointTime(long routepointTime) {
this.routepointTime = routepointTime;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
For some reason, the RoutePointRealm are added to the list, but all of its fields are set to zero and null. I have debugged my app to make sure that all of the parameters contains the correct values with the right datatypes etc. So now I know that the problem is related to the Realm methods.
What am I doing wrong?

First of all, thank you for your answers! I still couldn't get it to work after changing the solutions you've proposed. At least I didn't think so.
The reason I thought it didn't work, was partly because of a mistake that I made with my gui showing a zero value.. This made me to go into debugging the app, but apparently the debugger always shows zero or null values for the Realm objects.. At least in my case.
So at last, I tried making a Toast message with a fetched value from Realm and it returned what it was supposed to.
So I don't think that there were any problems to begin with.. The debugger just got me thinking so. I am sorry if I wasted your time, but I still thought that I should post this as an answer if other were to encounter the same problem.

All your objects are managed by Realm, so you don't need the realm.copyToRealmOrUpdate(routeRealm); call.

the problem comes from ID, Realm not support auto increment behaviour so you should do it manually.
something like :
beginTransaction()
foo.setId(value)
commitTrasaction()

My personal recommendation:
public void insertNewRoute(final int routeId, final long routeDate) {
final RouteRealm routeRealm = new RouteRealm();
realm.executeTransaction(new Realm.Transaction() {
#Override
public void execute(Realm realm) {
routeRealm.setId(routeId);
routeRealm.setDate(routeDate);
realm.insertOrUpdate(routeRealm);
}
});
}
public void insertNewRoutePoint(final int routeId, final String address, final float latitude,
final float longitude, final long routePointId, final long routePointTime) {
realm.executeTransaction(new Realm.Transaction() {
#Override
public void execute(Realm realm) {
RouteRealm routeRealm = realm.where(RouteRealm.class).equalTo(RouteRealmFields.ID, routeId).findFirst();
RoutePointRealm routePointRealm = new RoutePointRealm();
routePointRealm.setAddress(address);
routePointRealm.setLatitude(latitude);
routePointRealm.setLongitude(longitude);
routePointRealm.setRoutePointID(routePointId);
routePointRealm.setRoutepointTime(routePointTime);
routePointRealm = realm.copyToRealmOrUpdate(routePointRealm);
routeRealm.getRoutePoints().add(routePointRealm);
}
});
}

Related

Counters custom conflict resolution in realm mobile platform for android

I want to set a custom resolution for this scenario:
1- increment an integer field in realmobject in one device in offline mode
2- increment the same integer field in same realmobject in another device in offline mode
The default custom resolution is last update wins but in my case I want
the increment in both devices take effect on result after going live not last update.
I tried this code for test:
Realm realm = Realm.getDefaultInstance();
final RealmResults<Number> results= realm.where(Number.class).findAll();
realm.executeTransaction(new Realm.Transaction() {
#Override
public void execute(Realm realm) {
int num = results.get(0).getNumber()+1;
results.get(0).setNumber(num);
}
});
the Number class is like this:
public class Number extends RealmObject {
#PrimaryKey
private String id;
private int number;
public String getId() {
return id;
}
public void increment(){
this.number++;
}
public void setId(String id) {
this.id = id;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
This problem is very crucial to my app. If I can't do this in client side
I will not be able to use realm mobile platform which I was get so interested in.
Maybe you can use list of commands for such objects, persist them in offline and sync/merge on going online. Commands can be something like increment, decrement, multiplyBy2 and so on.
Documentation says:
Inserts in lists are ordered by time.
If two items are inserted at the same position, the item that was
inserted first will end up before the other item. This means that
if both sides append items to the end of a list they will end up in
order of insertion time.
So you will always have list of applied commands sorted by date.
The documentation currently says that counters are supported by the protocol but not exposed at the language level yet, so I guess you will have to implement it yourself.
The easiest way will be to just store it as a List of integers (1 for increment, -1 for decrement), and then use List.sum() (https://realm.io/docs/java/2.2.1/api/io/realm/RealmList.html#sum-java.lang.String-) to quickly get the aggregate result.
public class Counter extends RealmObject {
private int count;
public int getCount() { return count; }
public void setCount(int count) { this.count = count; }
}
public class Number extends RealmObject {
#PrimaryKey
private String id;
private RealmList<Counter> counters;
public void incrementNumber(){
Counter c = realm.createObject(Counter.class);
c.setCount(1);
this.getCounters().add(c);
}
public int getNumber() {
// Get the aggregate result of all inc/decr
return this.getCounters().sum("count");
}
public void setNumber(int number) {
this.getCounters().deleteAllFromRealm();
Counter c = realm.createObject(Counter.class);
c.setCount(number);
this.getCounters().add(c);
}
public String getId() { return id; }
public void setId(String id) { this.id = id; }
private RealmList<Counter> getCounters() { return counters; }
private void setCounters(RealmList<Counter> counters) { this.counters = counters; }
}
```
Thanks to #ast code example. I also solved the problem by caching command pattern here is my code:
public class CommandPattern extends RealmObject {
#PrimaryKey
private String id;
private String commandName;
public String getCommandName() {
return commandName;
}
public void setCommandName(String commandName) {
this.commandName = commandName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_increment:
if (isOnline()) {
realm = Realm.getDefaultInstance();
realm.executeTransaction(new Realm.Transaction() {
#Override
public void execute(Realm realm) {
updateNumberOnRealm();
}
});
realm.close();
} else {
addMethodToCache("increment");
}
public void addMethodToCache(final String methodName) {
realm = Realm.getDefaultInstance();
realm.executeTransaction(new Realm.Transaction() {
#Override
public void execute(Realm realm) {
commandPattern = new CommandPattern();
commandPattern.setId(UUID.randomUUID().toString());
commandPattern.setCommandName(methodName);
realm.copyToRealmOrUpdate(commandPattern);
}
});
realm.close();
}
public void invokeCachedCommands() {
realm = Realm.getDefaultInstance();
commandsCached = realm.where(CommandPattern.class).findAll();
commandsCached.addChangeListener(new RealmChangeListener<RealmResults<CommandPattern>>() {
#Override
public void onChange(final RealmResults<CommandPattern> element) {
if(!element.isEmpty()) {
realm.executeTransaction(new Realm.Transaction() {
#Override
public void execute(Realm realm) {
for (CommandPattern command : element) {
if(command != null) {
if (command.getCommandName().equals("increment")) {
//updateNumberOnRealm();
RealmResults<Number> results = realm.where(Number.class).findAll();
results.get(0).increment();
command.deleteFromRealm();
}
}
}
}
});
}
}
});
realm.close();
}
before getting increment action done I check online state and if it is offline the increment string cached in Command Pattern object
after going online again those cached commands get invoked by following code:
IntentFilter intentFilter = new IntentFilter(NetworkStateChangeReceiver.NETWORK_AVAILABLE_ACTION);
LocalBroadcastManager.getInstance(this).registerReceiver(new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
boolean isNetworkAvailable = intent.getBooleanExtra(IS_NETWORK_AVAILABLE, false);
if (isNetworkAvailable) {
invokeCachedCommands();
}else{
if(commandsCached != null) {
commandsCached.removeChangeListeners();
}
}
}
}, intentFilter);
this is general custom conflict resolution and can be used for any type of command

Error in passing data between activites android while using a custom object

when I pass this object with intent, its not starting the activity.
Custom object code
public class UserVo implements Serializable {
String name,id;
String can_reply,can_view;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public String getCan_reply() {
return can_reply;
}
public void setCan_reply(String can_reply) {
this.can_reply = can_reply;
}
public String getCan_view() {
return can_view;
}
public void setCan_view(String can_view) {
this.can_view = can_view;
}
public void setId(String id) {
this.id = id;
}
Sending data through the intent
intent.putExtra("UserVo",vo);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
Receiving data
intent=getIntent();
UserVo vo= (UserVo) intent.getSerializableExtra("UserVo");
I also tried bundle, but it still does not work.
Look at this link Serializable:
Every serializable class is assigned a version identifier called a serialVersionUID. By default, this identifier is computed by hashing the class declaration and its members. This identifier is included in the serialized form so that version conflicts can be detected during deserialization. If the local serialVersionUID differs from the serialVersionUID in the serialized data, deserialization will fail with an InvalidClassException.
To avoid it:
You can avoid this failure by declaring an explicit serialVersionUID. Declaring an explicit serialVersionUID tells the serialization mechanism that the class is forward and backward compatible with all versions that share that serialVersionUID. Declaring a serialVersionUID looks like this: private static final long serialVersionUID = 0L;
and remember that:
If you declare a serialVersionUID, you should increment it each time your class changes incompatibly with the previous version. Typically this is when you add, change or remove a non-transient field.
For best practise, I recommend you to use Parcelable. It's harder for coding but better for performance.
If for some reason, you can't make your object a Parcelable, try adding a serialVersionUID. You can generate it through your IDE or choose one yourself.
For UserVo you will have
UserVo implements Parcelable {
...
...
public UserVo (){
}
#Override public int describeContents() {
return 0;
}
#Override public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
+ other data ...writInt etc
}
public void readFromParcel(Parcel source){
name = source.readString();
+ other data ..keep the same order
}
public static final Parcelable.Creator<DocumentFile> CREATOR = new Parcelable.Creator<UserVo>() {
#Override
public UserVo createFromParcel(Parcel source) {
return new UserVo(source);
}
#Override
public UserVo[] newArray(int size) {
return new UserVo[size];
}
};
public UserVo(Parcel source )
{
readFromParcel(source);
}
Also have a look at annotations library , it will be easly to send data using #Extra annotation .
In order to send the custom objects from one Activity to Other, you have to serialize the objects with serialVersionID. Try the below modified code for your requirement.
UserVo.java
public class UserVo implements Serializable {
private static final long serialVersionUID = 1L;
String name,id;
String can_reply,can_view;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public String getCan_reply() {
return can_reply;
}
public void setCan_reply(String can_reply) {
this.can_reply = can_reply;
}
public String getCan_view() {
return can_view;
}
public void setCan_view(String can_view) {
this.can_view = can_view;
}
public void setId(String id) {
this.id = id;
}
ActivityA.java - To send the object through Intent
Intent objectIntent = new Intent(ActivityA.this, ActivityB.class);
i.putExtra("sendObjects", UserVo ); //Your object here
startActivity(objectIntent);
ActivityB.java - To Receive the Intent
UserVo mReceiveObjects = (UserVo)getIntent().getExtras().get("sendObjects");

EXTRA with parcelable comes out NULL but without its fine

I am getting a bit frustrated with an issue that I cannot seem to fully understand.
I have a listview with items and when I click them I want to pass an object (Parcelable) to a new activity. This is the code below:
lv_Entries.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent getItchesScreen = new Intent(Home.this, Itches.class);
getItchesScreen.putExtra("i", 3);
Entry e = entries.get(position);
getItchesScreen.putExtra("entry", e);
startActivity(getItchesScreen);
}
});
Now, I have the "i" extra there for debugging purposes. I was just sending "entry" and when I got the intent on the activity it didn't work. Code below:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_itches);
tv_date = (TextView) findViewById(R.id.tv_date);
Bundle b = getIntent().getExtras();
entry = b.getParcelable("entry");
tv_date.setText(entry.getDate());
itches = entry.getItches();
itchesAdapter = new ItchAdapter(this, itches);
ListView lv_Itches = (ListView) findViewById(R.id.lv_itches);
lv_Itches.setAdapter(itchesAdapter);
}
So when I read my bundle there is nothing at all. No "entry" key and no "i" key (I debugged to read i using watch feature)
BUT! If I don't send "entry" and only send "i" and I debug to catch "i" I do get it!
I have no idea why sending entry is ruining things but I cannot find any answer. I debugged the object and it does find it though .get(position).
Hope anyone can give me any ideas, and sorry for any trouble.
EDIT
Below is the code for Entry:
public class Entry implements Parcelable{
private String date;
private ArrayList<Itch> itches;
public Entry(String date){
this.date = date;
itches = new ArrayList<Itch>();
}
// PARCELABLE
public Entry(Parcel source){
date = source.readString();
source.readTypedList(itches, Itch.CREATOR);
}
public void AddItch(Itch itch){
itches.add(itch);
}
// get intensity average for the itches
public int IntensityAverage(){
int intensity = 0;
for(Itch i : itches){
intensity += i.getIntensity();
}
return intensity/itches.size();
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public ArrayList<Itch> getItches() {
return itches;
}
public void setItches(ArrayList<Itch> itches) {
this.itches = itches;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(date);
dest.writeTypedList(itches);
}
public static final Parcelable.Creator<Entry> CREATOR =
new Parcelable.Creator<Entry>() {
public Entry createFromParcel(Parcel source) {
return new Entry(source);
}
public Entry[] newArray(int size) {
return new Entry[size];
}
};
}
Itch class is also Parceable. I am populating correctly (no crashes on Android at least) the ListView with it.
For convenience I place the code here aswell:
public class Itch implements Parcelable{
private String time;
private String local;
private int intensity;
public Itch(String time, String local, int intensity){
this.time = time;
this.local = local;
this.intensity = intensity;
}
// PARCELABLE
public Itch(Parcel source){
time = source.readString();
local = source.readString();
intensity = source.readInt();
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getLocal() {
return local;
}
public void setLocal(String local) {
this.local = local;
}
public int getIntensity() {
return intensity;
}
public void setIntensity(int intensity) {
this.intensity = intensity;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(time);
dest.writeString(local);
dest.writeInt(intensity);
}
public static final Parcelable.Creator<Itch> CREATOR =
new Parcelable.Creator<Itch>() {
public Itch createFromParcel(Parcel source) {
return new Itch(source);
}
public Itch[] newArray(int size) {
return new Itch[size];
}
};
}
Alright so... What was the problem? Simple.
The reason why the parcelable always came out null was because a stupid error was occurring. Which error?
Well, okay so take a look at this piece of code:
entry = b.getParcelable("entry");
What is it saying? It is saying that entry will be equal to the parcelable "entry" key. But what does that really mean? Look at entry constructor.
// PARCELABLE
public Entry(Parcel source){
date = source.readString();
source.readTypedList(itches, Itch.CREATOR);
}
So when you say that entry is equals to a parcelable, then you will call this constructor in the Entry class that I have posted. But why is it wrong you might ask?
Well, so take a look. We're giving ArrayList itches to the method readTypeList. but... wait a second. If that is a constructor that means that we're building from 0... So... is itches initiated? No it is not! Because I was only initiating itches in the "normal" constructor!
public Entry(String date){
this.date = date;
itches = new ArrayList<Itch>();
}
So the solution is...
// PARCELABLE
public Entry(Parcel source){
date = source.readString();
//add this if condition!
if (itches == null) {
itches = new ArrayList<Itch>();
}
source.readTypedList(itches, Itch.CREATOR);
}
And thats it. That fixes our problem! :)
If other error occurs please be aware:
Make SURE that your key is correct. So check out for any typos in your getting extras.
entry = b.getParcelable("entyr");
as instead of
entry = b.getParcelable("entry");
And any other type of error like that.
That is not a good practive, you should have a variable that has the "entry" written on it so you never have this type of error mistakes. I have it in my code because I am fast-programming to build up a prototype :)
Happy coding!
have you tried doing this in onCreate()
Intent i = getIntent();
if(i.hasExtra("entry")){
entry = i.getParcelableExtra("entry");
}else{
Log.v("EXTRAS", "entry not found");
}

Android - Saving custom object - Shared Preferences or Database?

I'm creating a location based reminder application.
I've got a custom object called Reminder, which stores latitude, longitude, the location name and the subject of the reminder - Aswell as what profile it belongs to.
I'm then inputting the location name and sujbect into a ListView (Using cardlibs here too).
However now I need to save the data for when I close the application, and was wondering the best way to go about this - Do I store the entire 'Reminder' object or do I just store multiple pieces of data in Shared Preferences / A database.
This is my code - It's very inefficient/Ugly:
Reminder:
public class Reminder implements Parcelable {
public double latitude;
public double longitude;
public String subject;
public String locationName;
public String profile;
public Reminder() {
}
public Reminder(Parcel in) {
String[] data = new String[5];
in.readStringArray(data);
this.subject = data[0];
this.locationName = data[1];
this.latitude = Double.parseDouble(data[2]);
this.longitude = Double.parseDouble(data[3]);
this.profile = data[4];
}
public String getProfile() {
return profile;
}
public double getLatitude() {
return latitude;
}
public String getLocationName() {
return locationName;
}
public double getLongitude() {
return longitude;
}
public String getSubject() {
return subject;
}
public void setProfile(String profile) {
this.profile = profile;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public void setSubject(String subject) {
this.subject = subject;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringArray(new String[] { this.subject, this.locationName,
String.valueOf(this.latitude), String.valueOf(this.longitude), this.profile });
}
public static final Parcelable.Creator<Reminder> CREATOR = new Parcelable.Creator<Reminder>() {
public Reminder createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new Reminder(source); // using parcelable constructor
}
public Reminder[] newArray(int size) {
// TODO Auto-generated method stub
return new Reminder[size];
}
};
}
List using a fragment:
public class HomeFragment extends Fragment {
public static ArrayList<Card> cards = new ArrayList<Card>();
Reminder reminder;
public HomeFragment() {
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
reminder = getActivity().getIntent().getParcelableExtra("reminder");
Card card = new Card(getActivity());
CardHeader cardHeader = new CardHeader(getActivity());
if (reminder != null) {
cardHeader.setTitle(reminder.getSubject());
card.addCardHeader(cardHeader);
card.setTitle(reminder.getLocationName());
cards.add(card);
}
CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(
getActivity(), cards);
CardListView listView = (CardListView) getActivity().findViewById(
R.id.card_list);
mCardArrayAdapter.notifyDataSetChanged();
if (listView != null)
listView.setAdapter(mCardArrayAdapter);
}
Any criticism on how my code could of been wrote better would also be really beneficial, as I feel I'm being a huge rookie and missing something obvious which would make it more efficient.
Thanks!
Basically the choice to use shared preferences vs a database hinges on a number of things:
1) How many objects are we talking about? How complex are they?
2) Do you intend on searching/manipulating these objects or are you just saving/loading them.
3) Do you intend to export/move/send objects?
4) Do you want the objects to be recoverable across application contexts - that is beyond only the single app in question.
In your specific case I would use a database.
http://developer.android.com/guide/topics/data/data-storage.html#pref
As you can see in the docs here prefs isn't really intended for Object storage - it's for key value pairs. While you could store an object as a number of key value pairs in the shared prefs and reconstruct from there, you would have to go through some weird model conversions to do this for multiple objects. In short it doesn't really make sense.

How to Pass Custom Arraylist content from one Activity to another Activity in android

i have an objects in an custom arraylist as "finaljsoncontent", and now i am trying to pass this "finaljsoncontent" array to another Activity, and i have also tried getters and setters, and also bundle, but i cant, help me how to do this.
Thanks in advance.
Check this out: How do I pass an object from one activity to another on Android?
Your class "JSonKey" should implement parcealable or serializable so that Android can "send" it from an activity to the other activity.
You could try implementing Parcelable, then you can pass it in a bundle. You will need to reduce your object to mostly primitive types to do this. Otherwise you can extend the Application class and store it there. You would retrieve that using the call to getApplicationContext(). Or, of course, you could always create some sort of static globals class that all of your classes can reference.
Here is one of my implementations of parcelable..
package warrior.mail.namespace;
import android.os.Parcel;
import android.os.Parcelable;
public class JView implements Parcelable {
public String subject;
public String from;
public boolean unread;
public String body;
public int inboxIndex;
private long id;
public static final Parcelable.Creator<JView> CREATOR = new Parcelable.Creator<JView>() {
public JView createFromParcel(Parcel in) {
return new JView(in);
}
public JView[] newArray(int size) {
return new JView[size];
}
};
public JView(){
body = "";
}
public JView(String subject,String from,boolean unread){
body = "";
this.subject = subject;
this.from = from;
this.unread = unread;
}
public JView(Parcel parcel){
subject = parcel.readString();
from = parcel.readString();
body = parcel.readString();
unread = parcel.createBooleanArray()[0];
inboxIndex = parcel.readInt();
}
#Override
public int describeContents() {
return inboxIndex;
}
#Override
public void writeToParcel(Parcel out, int arg1) {
out.writeString(subject);
out.writeString(from);
out.writeString(body);
boolean[] array = new boolean[] {unread};
out.writeBooleanArray(array);
out.writeInt(inboxIndex);
}
public void setIndex(int index){
inboxIndex = index;
}
public void setUnread(boolean arg){
unread = arg;
}
public void setContent(String content){
body = content;
}
public void setSubject(String subject){
this.subject = subject;
}
public void setFrom(String f){
from = f;
}
public void setId(long arg){
id = arg;
}
public long getId(){
return id;
}
public void updateIndex(){
}
}
You can either make your class Parcelable(android specific) or make it serializable like in java(just write implements Serializable with your class)

Categories

Resources