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

  • Home
  • SEARCH
  • 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 9205607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:59:18+00:00 2026-06-17T23:59:18+00:00

so i get the main idea of how to use protected void onSaveInstanceState (Bundle

  • 0

so i get the main idea of how to use

  protected void onSaveInstanceState (Bundle outState)

http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)

also from Saving Android Activity state using Save Instance State

but my problem is what if this was the first time the application is being created? then nothing would have been stored in the bundle before….and if so then when i try to call something out from the bundle that hasn’t been saved before what do i get?null?
for example
i have this in my code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String [] b=savedInstanceState.getStringArray("MyArray");
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    String [] a={"haha"};
    savedInstanceState.putStringArray("MyArray", a);
}

in the FIRST time the application is ever opened what would the value of b be?
and after the application has been used once what would the value of b be?

Many thanks!

  • 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-17T23:59:20+00:00Added an answer on June 17, 2026 at 11:59 pm

    in your onCreate()
    add a condition

     if(savedInstanceState==null){
      //meaning no data has been saved yet or this is your first time to run the activity.  Most likely you initialize data here.
     }else{
       String [] b=savedInstanceState.getStringArray("MyArray");
     }
    

    by the way to retrieve data that was saved in your onSaveInstanceState you will override this

     @Override
     protected void onRestoreInstanceState(Bundle savedInstanceState) {
       // TODO Auto-generated method stub
      super.onRestoreInstanceState(savedInstanceState);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this website: http://theoew.uuuq.com/portfolios/Idea/ I use Cufon to style the text for the the
I've been trying to learn about metaclasses in Python. I get the main idea,
Can I capture the following two routes in a single line? GET /game controllers.Main.app.gamelist
Main idea to put these question is get exact features of SQL Server 2008
folks! I'm implementing a shared cache in my app. The idea is to get
I want to use simple snmp get in android.I found the code for java
How would I get the main program to recognize that I have an outside
I try to get the main window handle using following code in Lazarus (Free
I get the following error main.c:107:2: internal compiler error: in extract_for_fields, at cilk-spawn.c:1857 }
My main problem is I don't understand how to get the position of the

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.