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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:07:56+00:00 2026-06-16T18:07:56+00:00

There is an Activity and some variable’s. They are passed from previous one. The

  • 0

There is an Activity and some variable’s. They are passed from previous one.
The senerio is :-
When users click home button and back to main screen ,after a while users click the application icon to go back to the app , the app crashed. I think that’s because Android system killed the activity or something else and then it tries to do the onCreate() , and unfortunatly there is a NullpointerException so the app crashed.

Any idea to fix this or what should I do with this exception?
Thanks.

Please allow me to wish you Merry Christmas ahead of the time.

  • 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-16T18:07:59+00:00Added an answer on June 16, 2026 at 6:07 pm

    When you press “home”, control goes to the Home application, and the current application is pushed to the background. Android may kill the process at any time to reclaim memory.

    When you return to the Activity, it might be the same instance (if Android didn’t kill the process) or it might be a new instance of the Activity.

    The same thing can happen if memory is very tight and you progress forward from an Activity; the Activity could be released. When you press Back, you may have the same problem.

    If you want to keep data, you should use onSaveInstanceState(Bundle) to store any data that you want to recover.

    Notice that onCreate() takes a Bundle as an argument. If the Activity was paused (such as happens when you press Home), onSaveInstanceState() is called to allow you to store data temporarily, and that same data is passed back into onCreate(). If the Activity is being launched fresh, that bundle will be null.

    So you should do something like:

    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        // store data in the bundle
    }
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
            // read old data from the Bundle
        } else {
            // you're starting clean; no saved data
        }
        ...
    }
    

    A few notes:

    • All data stored in the Bundle must be primitive, Serializable, or better, Parcelable
    • Data in Android’s Views that has an android:id set is automatically stored in the bundle and retreived when the Activity is recreated (for example, data typed in an EditText will be saved for you)
    • Other data that is not part of and Android View will not be saved automatically, nor will data in your custom Views

    Hope this helps!

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

Sidebar

Related Questions

I'am starting a child activity on click of a button from Parent. And i'am
I have some problem with Android AsyncTask. There is an Activity which contains some
Is there a way to vizualise the activity stack, at some moment during debug,
In my activity there is a toggle button. I want every time you change
After tracing the DB activity from a DNN 5.2.3 site I noticed that there
I've got an activity, where I initialize some static variable (Menu of the app).
Is there a way to pass OutArgument value of one activity to InArgument of
I have an activity that is started from another activity via a button and
I am trying to send the events from one Java class to Activity. Scenario
Alright, so i have an Activity. In the activity there is a textview and

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.