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 8508299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:07:27+00:00 2026-06-11T03:07:27+00:00

Why do I need to parcel my object even if I just need to

  • 0

Why do I need to parcel my object even if I just need to send it to another thread of the same task? Actually I need to open an activity that will run even on the same thread (the main thread).

In other words why didn’t Google provide a version of startActivity that take a generic object ad parameteer instead of a bundle to let me start an activity in case I know it is within the same process or (most of the times) even the same thread (the main one)?

  • 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-06-11T03:07:29+00:00Added an answer on June 11, 2026 at 3:07 am

    You don’t need to use Parcelable to pass an object from one activity to another. You can just store a reference to the object in a static member variable, like this:

    public class Globals {
         public static MyObject myObject;
    }
    

    Now, in the code that has the object, you just do:

    Globals.myObject = object;
    

    and in the new activity, you can get it like this:

    doSomethingWith(Globals.myObject);
    

    Now, having said that, you need to be aware of the following:

    Android can kill your process if your application is in the background pretty much any time it wants to. When the user then returns to your application, Android will create a new process for your application and then it will recreate only the activity that was on the top of the activity stack (ie: the one that was showing). In that case, the newly created activity will not be able to get the iobject by accesing Globals.myObject because the process has been newly created and that member variable is null.

    To get around this you can either:

    1. Determine that your process has been killed and restarted (by checking Globals.myObject == null and react accordingly – Tell the user he needs to go back, or just go back yourself, or show a dialog or whatever)
    2. Save the object when Android calls onSaveInstanceState() in your activity (which Android will do before sending your app to the background) and restore the object in onCreate()

    Hopefully this both answers your question and explains what to do about it.

    EDIT: Add more information about why Intents contain serialized (Parcelable) objects and not the objects themselves

    1. When you call startActivity() or startService() Android may end up starting the activity or service in another process. In this case, if you passed an object in the Intent, Android would somehow need to serialize that object to pass it to the other process. Because of the "implicit Intent resolution" that Android uses to determine which component gets to handle the Intent, the caller may or may not know which component will get started.

    2. Android saves the contents of Intents for various reasons:

      A. Android can kill a process at any time. If it does that and the user wants to return to the application, Android creates a new process and then recreates the activities in that process as needed. To create the activities Android also needs to make the Intents available to the activities. If the process has been killed then any "objects" in the Intents would have to be saved and restored. Because the Intents contain serialized objects, it isn’t a problem to recreate these as needed.
      B. PendingIntents are use by Android as a way for the Operating System to act as a proxy for the sender of an Intent. An Android component can create a PendingIntent and give that to the Operating System so that it can trigger the sending of that Intent at some later time. The sending component may or may not be active at the time that the PendingIntent is actually sent. This means that any object that could be passed in a PendingIntent must be able to be serialized so that Android can hold on to it even if the calling component no longer exists.

    3. Intents are not intended as a general "parameter passing" mechanism between components. Of course you can use it like that, but you can also use other (easier) mechanisms. Within a given process you can pass objects around using standard Java mechanisms. There is nothing wrong with using static (class) variables for this.

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

Sidebar

Related Questions

Need help with an error message that I just can't figure out. I am
Need just a push in the right direction with this. I'm building a multi-language
Need help with a query that I wrote: I have three tables Company id
need a little help with this one. I have a form that I am
need to open an excel sheet and then go an to cell range like
Need something simulat jcrop plucgin (link to example is here: http://publikz.com/one-more-task-rounded-selection-in-jquery/ ) but with
Need a div to partially show the image behind it, is this even possible?
Need to send and receive a SOAP message in the following format from a
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either

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.