parcelable

Parcelable custom handler, message never received

百般思念 提交于 2020-01-06 13:58:46
问题 I want to parcelable a Handler object to send it by a Bundle from one Activity to a service in order to get some info from this service. Right now, to test it it's a simple message. Here's the code in the Activity: private MyHandler mHandlerSharing = new MyHandler() { public void handleMessage(Message msg) { // this line in the Activity is never reached when debugging String data = msg.getData().getString("data"); Toast.makeText(mContext, data, Toast.LENGTH_SHORT).show(); } }; // in some

How to send an object to another activity with special stuff?

别来无恙 提交于 2020-01-06 04:22:24
问题 I am developing a math app for kids. After the user customizes the question options, I want to start another activity. I want to send a QuestionOptions object to the activity so that it can generate questions according to the options. So I created a QuestionnOptions class and implement Parcelable as the other answers showed me. However, there is an enum in my class. So I don't know what to do and let Android Studio generate the stuff needed: package com.smartkidslovemaths; import android.os

Not able to send an Arraylist of objects using putparcelablearraylist to the fragment through bundle?

不羁的心 提交于 2020-01-05 10:25:41
问题 I have been trying to send an Arraylist of objects using putparcelablearraylist to the fragment through bundle. But I am getting the value of savedinstancestate as null and I am hence not able to retrieve the list values. Is there anything wrong with my implementation?? Bundle is taken the parameters but when I am trying to receive the arraylist of objects in the fragment, I am getting the value of the savedinstance state as null. Following is the code for my MainActivity:- public class

Android: convert Parcelable to JSON

∥☆過路亽.° 提交于 2020-01-05 03:39:06
问题 I am working with socket.io library which emits messages to the socket.io server. The server expects JSON objects, arrays, etc. My original implementation used JSONOject and JSONArray datatypes. However, I would like to switch to using classes generated via Parceler library. The classes generated with library's annotations can be wrapped into Parcels. It seems like a very convenient way of managing such communication. However, is there a way to convert Parceler's class or a Parcel class into

Android : Make this object as Parcelable

天涯浪子 提交于 2020-01-04 06:52:38
问题 I have an object that I need to pass between 2 Activity . The object has HashTable, String[], etc. Can't make out how to make it Parcalebale so that I can populate an array of the object and pass single obj or array to other Activity. My class is : public class TrainRoute { // implements Parcelable private String RouteName; private int RouteIndex; private Context ctx; private Hashtable<String, String> stationsList; private String[] stationsNames; private String[] trainTimings; private boolean

Write enum with String to parcel

浪子不回头ぞ 提交于 2020-01-03 07:50:30
问题 I had Parcelable enum like this: public enum Option implements Parcelable { DATA_BASE, TRIPS, BIG_PHOTOS, OLD_PHOTOS, FILTERS_IMAGES, CATEGORIES_IMAGES, PAGES, SOUNDS, PUBLIC_TRANSPORT, MAPS; public static final Parcelable.Creator<Option> CREATOR = new Parcelable.Creator<Option>() { public Option createFromParcel(Parcel in) { return Option.values()[in.readInt()]; } public Option[] newArray(int size) { return new Option[size]; } }; @Override public int describeContents() { return 0; }

Saving/Restoring custom ArrayList on Android screen rotate?

北慕城南 提交于 2020-01-03 04:43:26
问题 I have a custom ArrayList of MovieItems that I want to save and restore on screen rotation. I checked out this post - How to save custom ArrayList on Android screen rotate? - and implemented and adapted some of the codes but the saving and restoring don't seem to be working for me. 1) Saving the ArrayList: public List<MovieItem> mItems = new ArrayList<>(); @Override public void onSaveInstanceState(Bundle outState) { outState.putParcelableArrayList(MOVIE_KEY, (ArrayList<? extends Parcelable>)

Android implement Parcelable objects with hashmap that contains another hashmap

[亡魂溺海] 提交于 2020-01-02 10:59:51
问题 This is an extension for Android implement Parcelable object which has hashmap but mine is a little different. I have these classes public class EventDetails implements Parcelable { Private String id; Private String eventName; Private Long eventUnixTime; Private HashMap <String, User> pickedUser = null; } and public class User implements Parcelable { private String email; private String userName; private String userPicture; private Boolean hasLoggedInWithPassword; private HashMap<String,

Android implement Parcelable objects with hashmap that contains another hashmap

强颜欢笑 提交于 2020-01-02 10:59:16
问题 This is an extension for Android implement Parcelable object which has hashmap but mine is a little different. I have these classes public class EventDetails implements Parcelable { Private String id; Private String eventName; Private Long eventUnixTime; Private HashMap <String, User> pickedUser = null; } and public class User implements Parcelable { private String email; private String userName; private String userPicture; private Boolean hasLoggedInWithPassword; private HashMap<String,

Writing arrays of Parcelables to a Parcel in Android

北城以北 提交于 2020-01-02 03:33:08
问题 I'm trying to write an array of objects that implement Parcelable into a Parcel using writeParcelableArray. The objects I'm trying to write are defined (as you'd expect) as: public class Arrival implements Parcelable { /* All the right stuff in here... this class compiles and acts fine. */ } And I'm trying to write them into a `Parcel' with: @Override public void writeToParcel(Parcel dest, int flags) { Arrival[] a; /* some stuff to populate "a" */ dest.writeParcelableArray(a, 0); } When