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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:45:24+00:00 2026-06-09T21:45:24+00:00

I program my first Android app and am very new to Android development (as

  • 0

I program my first Android app and am very new to Android development (as well as Java). I have PreferenceActivity and noticed that when activity is shown and I turn off mobile its onCreate() is called once again. Even more confusing is that static member MyFirstAppActivity.camera is not existing anymore causing exceptions. I can put check for null in there but I wonder why is this happening and whats the best way to avoid it?

public class SettingsActivity extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

     // Root
        addPreferencesFromResource(R.xml.preferences);

        // get list of available resolutions

        Object[] previewSizes = MyFirstAppActivity.camera.getParameters()
                .getSupportedPreviewSizes().toArray();

        // split object properties into two arrays

        String[] ps=new String[previewSizes.length];

        for(int i=0;i<previewSizes.length;i++)
        {
            try
            {
                int width=((Size)previewSizes[i]).width;
                int height=((Size)previewSizes[i]).height;
                ps[i]=width+"x"+height;
            }
            catch(Exception ex)
            {}
        }

        // get list of available resolutions

        Object[] recordingSizes = MyFirstAppActivity.camera.getParameters()
                .getSupportedPictureSizes().toArray();

        // split object properties into two arrays

        String[] rs=new String[recordingSizes.length];

        for(int i=0;i<recordingSizes.length;i++)
        {
            try
            {
                int width=((Size)recordingSizes[i]).width;
                int height=((Size)recordingSizes[i]).height;
                rs[i]=width+"x"+height;
            }
            catch(Exception ex)
            {}
        }

        Preference prefPreviewSizes = getPreferenceManager().findPreference("previewSizes");
        Preference prefRecordingSizes = getPreferenceManager().findPreference("recordingSizes");

        ((ListPreference) prefPreviewSizes).setEntries(ps);
        ((ListPreference) prefRecordingSizes).setEntries(rs);

    }
}
  • 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-09T21:45:25+00:00Added an answer on June 9, 2026 at 9:45 pm

    Whenever some sort of state change happens (for example, turning off or rotating the screen) the onCreate method gets called.

    I’m pretty sure what you’re supposed to do is override the onSaveInstanceState method and save data to it’s outState Bundle, which then gets passed to onCreate as the savedInstanceState Bundle.

    For some more info, check out “Handling Runtime Changes” in the Android developer center.

    You might be able to keep your camera from causing exceptions by checking if it exists before creating it, something like

    if(MyFirstAppActivity.camera == null)
        MyFirstAppActivity.camera = new Camera(...);
    

    or just create a new instance of it in onCreate

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

Sidebar

Related Questions

I'm creating my first android app that will make use of SQlite. I have
I have an a Java Android app that calls different activities. I thought this
I am programming on an android app, and I have a program with a
I have a fully-functional Java program that's fairly long, and I want to transfer
I'm new to writing app for android. I've got program writing experience in non
I'm trying to program my first GUI-class in Java, using the Window Builder. Ok,
I am a frequent R user (the very first program I turn on everyday
I am currently trying to write a very simple app that sends an object
I'm working on my first Android app, and am almost to the point where
I have a compiling problem. I followed tutorial about Hello world program for Android

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.