Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6744017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:02:01+00:00 2026-05-26T12:02:01+00:00

I am developing simple travel agent android application. When application starts it loads list

  • 0

I am developing simple travel agent android application. When application starts it loads list of cities, in the next activity user will see source and destination spinners, once user selects proper source and destination, it will take to third activity, it displays available travels if user selects one it takes to fourth activity in which user selects seat and continues to book ticket. In order to maintain complete user session I am maintaining a UserSession class, which is as follows (removing unnecessary logic in the code which is irrelevant to problems)

    public class UserSession implements Parcelable {
        List<City> citiesList;
        HashMap<String, City> cityMap; // Map city name to code
        RouteSearchResult searchedRoutes;
        String sourceCity;
        String destinationCity;
        LocalStop selectedBoardingPoint;
        LocalStop selectedArrivalPoint;

        @Override
        public void writeToParcel(Parcel parcel, int flags) {
            try {
                parcel.writeList(citiesList);
                parcel.writeMap(cityMap);
                parcel.writeValue(searchedRoutes);
                parcel.writeString(sourceCity);
                parcel.writeString(destinationCity);
                parcel.writeValue(selectedBoardingPoint);
                parcel.writeValue(selectedArrivalPoint);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public class City implements Parcelable {
        String cityName;
        String cityId;
        @Override
        public void writeToParcel(Parcel parcel, int flags) {
            parcel.writeString(cityName);
            parcel.writeString(cityId);
        }
    }
    public class RouteSearchResult {
            City source;
            City destination;
            String date;
            List<RouteDetails> routeDetails;
    }

I have the following problems
1) I am getting run time exception while writing

W/System.err(  817): java.lang.RuntimeException: Parcel: unable to marshal value com.travelagent.City@40605878
W/System.err(  817):    at android.os.Parcel.writeValue(Parcel.java:1132)
W/System.err(  817):    at android.os.Parcel.writeList(Parcel.java:519)
W/System.err(  817):    at com.travelagent.UserSession.writeToParcel(UserSession.java:201)
W/System.err(  817):    at android.os.Parcel.writeParcelable(Parcel.java:1151)

2) I commented parcel.writeList(citiesList); statement to see if I get any more problems, I got similar problem with parcel.writeValue(searchedRoutes);

I have following questions,
1) How to make a list of custom objects as parcelable?
2) Is it mandatory to make custom class like City also parcelable, which is part of actual class to be parceled.
3) Is there any approach to solve this kind of problems like passing user session to all activities.

Please help, I searched, but I couldn’t find appropriate solution to make custom class parcelable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:02:01+00:00Added an answer on May 26, 2026 at 12:02 pm

    My understanding is that you shouldn’t use Parcels for this. From the android documentation on Parcels:

    Parcel is not a general-purpose serialization mechanism. This class (and the corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a high-performance IPC transport. As such, it is not appropriate to place any Parcel data in to persistent storage: changes in the underlying implementation of any of the data in the Parcel can render older data unreadable.

    What you should do is create two static methods for each class you want to transfer to the next activity. Call one of them toBundle() and one of them fromBundle(). The first converts a given instance of you class to a bundle while the second creates a new instance of your class from a bundle. Every time you need to pass an object on to the next Activity, just bundle it up using the toBundle() method and add it to the Intent you’re using to start the next Activity. In the next Activity, you can recreate the object by calling fromBundle().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a simple application for Android in which I am using a
i am developing one simple application for android mobile here i am using two
I'm developing a simple application for Android devices. I need to create a directory,
I am developing a simple Restaurant application in Android, I used menus and inflated
Hi I am developing a simple application based upon ASP.NET MVC. I have altered
I am developing a simple platform game in Java using BlueJ. Over the next
I am developing a simple web page to be viewed after an iphone application
i'm developing simple cms application. i want to integrate number of hits for some
I have 6 months experience with Android, developing simple UI-based applications. Now I want
Im developing a simple console application using java. I want to display currently running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.