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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:00:35+00:00 2026-05-27T17:00:35+00:00

Edit: If anbody wants an answer when onConfigurationChanged is called I just intialize all

  • 0

Edit: If anbody wants an answer when onConfigurationChanged is called I just intialize all the variables I did in onCreate

Hello I have an application the displays a progress dialog and then displays an image in an imageview that has been taken from the camera. The problem is when I take the picture in landscape, and then wait for the dialog to finish nothing shows up in any of the imageview, and none of the buttons work. It used to crash when the dialog was about to be displayed, but I fixed that. Here is some of my code:

public class AnnoyingMeterActivity extends Activity {

    Random r = new Random(System.currentTimeMillis());


    class ProgressThread extends Thread {
        Handler mHandler;
        final static int STATE_DONE = 0;
        final static int STATE_RUNNING = 1;
        int mState;
        int total;

        ProgressThread(Handler h) {
            mHandler = h;
        }

        public void run() {
            mState = STATE_RUNNING;
            total = 0;
            while (mState == STATE_RUNNING) {
                try {
                    Thread.sleep(55);
                } catch (InterruptedException e) {

                }
                Message msg = mHandler.obtainMessage();
                msg.arg1 = total;
                mHandler.sendMessage(msg);
                total++;
            }
        }

        /*
         * sets the current state for the thread, used to stop the thread
         */
        public void setState(int state) {
            mState = state;
        }
    }

    TextView tv;
    ImageView iv;
    TextView tv1;
    static final int PROGRESS_DIALOG = 0;
    ProgressThread progressThread;
    ProgressDialog progressDialog;
    Bitmap person;
    ImageView tiv;
    ImageView iv2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button scanPersonButton = (Button) findViewById(R.id.scanPerson);
        scanPersonButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                scanPerson();

            }
        });
        tv = (TextView) findViewById(R.id.tv);
        iv = (ImageView) findViewById(R.id.annoyingMeterImage);
        iv.setBackgroundResource(R.drawable.finalmeter);
        tv1 = (TextView) findViewById(R.id.textView1);
        tiv = (ImageView) findViewById(R.id.imageView1);


    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      setContentView(R.layout.main);
    }


    protected void scanPerson() {

        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        startActivityForResult(intent, 0);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            person = (Bitmap) data.getExtras().get("data");
            showDialog(PROGRESS_DIALOG);
        }

    }

    protected void randomImageDisplayThing() {
                tiv.setBackgroundDrawable(new BitmapDrawable(person));
        switch (annoyingRating) {
        case 0:
            iv.setBackgroundResource(R.drawable.finalmeter0);
            break;
        case 1:
            iv.setBackgroundResource(R.drawable.finalmeter1);
            break;
        case 2:
            iv.setBackgroundResource(R.drawable.finalmeter2);
            break;
        case 3:
            iv.setBackgroundResource(R.drawable.finalmeter3);
            break;
        case 4:
            iv.setBackgroundResource(R.drawable.finalmeter4);
            break;
        case 5:
            iv.setBackgroundResource(R.drawable.finalmeter5);
            break;
        case 6:
            iv.setBackgroundResource(R.drawable.finalmeter6);
            break;
        case 7:
            iv.setBackgroundResource(R.drawable.finalmeter7);
            break;
        case 8:
            iv.setBackgroundResource(R.drawable.finalmeter8);
            break;
        case 9:
            iv.setBackgroundResource(R.drawable.finalmeter9);
            break;
        case 10:
            iv.setBackgroundResource(R.drawable.finalmeter10);
            break;
        case 11:
            iv.setBackgroundResource(R.drawable.finalmeter11);
            break;
        }

    }

    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case PROGRESS_DIALOG:
            progressDialog = new ProgressDialog(this);
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setMessage("Scanning...");
            return progressDialog;
        default:
            return null;
        }
    }

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            int total = msg.arg1;
            progressDialog.setProgress(total);
            if (total >= 100) {
                dismissDialog(PROGRESS_DIALOG);
                progressThread.setState(ProgressThread.STATE_DONE);
                randomImageDisplayThing();
            }
        }
    };

    @Override
    protected void onPrepareDialog(int id, Dialog dialog) {
        switch (id) {
        case PROGRESS_DIALOG:
            progressDialog.setProgress(0);
            progressThread = new ProgressThread(handler);
            progressThread.start();
        }



    }
}

Now I really don’t know what to do. I think the problem might have something to do with the orientation change. Any help is appreciated!

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

    Try using AsyncTask instead of your custom thread. As some of the things are suppose to work on UI thread and rest on background thread and AsyncTask make that easy. Also debugging thread code just by looking at it is difficult as well as un-reliable.

    http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html
    http://developer.android.com/reference/android/os/AsyncTask.html

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

Sidebar

Related Questions

EDIT: This question is solved, but I can't accept my own answer just yet.
Edit: I solved it by getting all of the class variables using get_class_vars(), and
Edit: From another question I provided an answer that has links to a lot
Just started with JavaCC. But I have a strange behaviour with it. I want
I have an odd problem. There are two databases. One has all products in
I Have an Enum Called ActionStatus that has 2 possible values open=0 and closed
I might not have known what to search for to get this answer so
I have looked for the answer to this on Google and stackoverflow, but unfortunately
Does anybody know how to edit a syntax file for VIM so that keywords
Does anybody know a good Emacs mode to edit JSON? An app I am

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.