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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:48:55+00:00 2026-05-24T17:48:55+00:00

So I have 3 Activities that need to all have access to the same

  • 0

So I have 3 Activities that need to all have access to the same custom class object (let’s call it ‘a’) created by me when the very first Activity is created.

Because ‘a’ is made up of a whole bunch of non-primitives, I found it difficult to make Serializable or Parcelable. Instead I created a Service that binds to each Activity as they take the forefront, and gives the Activity ‘a’ in OnBind().

Now ‘a’ has a getter that gets another object of a different custom class stored with the same object (let’s call it ‘b’). In all three Activities, I also need to be able to access ‘b’.

If I start the first Activity, use a button to navigate to the second Activity, press the “home” button on my phone, then go back into the application by pressing its icon, then navigate to the third activity by pressing a button, I get a null pointer exception on ‘b’ but not ‘a’.

However if I add a line that prints ‘a’s getter for ‘b’ with sysout in the step where I press a button to get from the second Activity to the third, then there is no null pointer exception.

Does anybody know why this is and how I can resolve the issue?

  • 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-24T17:48:56+00:00Added an answer on May 24, 2026 at 5:48 pm

    Seems you want this object a to always be there!

    I suggest extending application

    public class YourApplication extends Application {
        YourObject A;
        @Override
        public void onCreate(){
            A = new YourObject();
        }
        //add getters or setters //
    }
    

    Now in your Activities:

    YourApplication app;
    app = app = ((YourApplication)getApplicationContext());
    

    Finally in your Mainfest: Add to <application>

    android:name=".YourApplication"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a database that I need to access in all activities. So
I've more than one activity (inside the same Application) that needs to have access
Think that I have many activities,and all I want is this: I have a
I have a class called UserContext that tracks the activities of a given user
I have a bunch of Workflow foundation 4.0 RC code activities that consume web
In my application I have several activities, the main screen has 4 buttons that
I need to decorate all the activities shown in designer with some icons or
How do I perform logging of all activities that are done by a Python
Another design question for you If I have 5 activities that can result from
Under some circumstances I need to be able to tear down all my activities

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.