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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:59:48+00:00 2026-06-09T14:59:48+00:00

In my activity I am setting all the Views like ImageView, TextViews with theirs

  • 0

In my activity I am setting all the Views like ImageView, TextViews with theirs respective data using AsyncTask.

after asyncTask.Execute();

I have a textView.onCLickListener which calls Camera and after the picture is taken, the ImageView in the activity is set to this pic.

But the problem is my asyncTask is called again after the onActivityResult();

Here is my complete Activity code:

public class UserProfileActivity extends Activity {

//many instance fiels here
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.user_profile);

        new LongOperation().execute("");

        userImage = (ImageView) findViewById(R.id.profileImage);
        userName = (TextView) findViewById(R.id.userName_profile);
        userLocation = (TextView) findViewById(R.id.userLocation_profile);
        editInfo = (TextView) findViewById(R.id.edit_profile);
        changeImage = (TextView) findViewById(R.id.changeImage_profile);
        userScore = (TextView) findViewById(R.id.userScore_profile);
        friendsLabel = (TextView) findViewById(R.id.userFriends_profile);


            changeImage.setOnClickListener(new View.OnClickListener() {

                public void onClick(View arg0) {
                    Intent cameraIntent = new Intent(
                            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(cameraIntent, CAMERA_REQUEST);
//Point 1
                }
            });
//Point 2
    }
    private class LongOperation extends AsyncTask<String, Void, String> {

        private InputStream is;
        private StringBuilder sb;
        private String result;
        private ProgressDialog dialog = new ProgressDialog(context);

        @Override
        protected String doInBackground(String... params) {

//Point 3
            try {
                HttpResponse response;

                    HttpPost httppost = new HttpPost(
                            "http://www.xxxxx.com/yyyy/zzzz");
                    //httpclient is global to maintain sessions
                    response = SignUpActivity.httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent();

                try {
                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(is, "iso-8859-1"), 8);
                    sb = new StringBuilder();
                    sb.append(reader.readLine() + "\n");
                    String line = "0";
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                    is.close();
                    result = sb.toString();
                } catch (Exception e) {
                    Log.e("error in reading input stream", e.toString());
                }
                try {
                    JSONObject jObj = new JSONObject(result);
                    String status = jObj.getString("status");
                    score = jObj.getInt("credits");
                    level = jObj.getInt("level");
                    image = jObj.getString("image");
                    fname = jObj.getString("fname");
                    lname = jObj.getString("lname");
                    city = jObj.getString("city");
                    email = jObj.getString("email");
                    clickedUserId = jObj.getInt("user_id");

                    JSONArray friendsJsonArray = jObj.getJSONArray("friends");
                    size = friendsJsonArray.length();

                    ArrayList<String> friendsNames = new ArrayList<String>();
                    friendsIds = new int[size];
                    for (int i = 0; i < size; i++) {

                        friendsNames.add(friendsJsonArray.getJSONObject(i)
                                .getString("name"));
                        friendsIds[i] = friendsJsonArray.getJSONObject(i)
                                .getInt("user_id");
                    }
                    adapter = new ArrayAdapter<String>(context,
                            R.layout.simple_listview_item, friendsNames);
                } catch (Exception e) {

                    Log.d("error in creating json object", e.toString());
                }
            } catch (Exception e) {
//Point 5
                Log.e("error main try", "Error in http connection" + e.toString());
            }
            return "Executed";
        }
        @Override
        protected void onPostExecute(String result) {

            friendsList.setAdapter(adapter);
            userScore.setText(score + " points" + "   level " + level);
            userName.setText(fname + "  " + lname);
            userLocation.setText(city);
            changeImage.setText("Change image");
            editInfo.setText("Edit");
            friendsLabel.setText("Friends");
            Bitmap bitmap = null;
            try {
                bitmap = BitmapFactory
                        .decodeStream((InputStream) new URL(image).getContent());
                userImage.setImageBitmap(bitmap);
            } catch (MalformedURLException e1) {

                e1.printStackTrace();
                userImage.setImageResource(R.drawable.xxx);
            } catch (IOException e2) {

                e2.printStackTrace();
                userImage.setImageResource(R.drawable.xxx);
            }

            if (dialog.isShowing()) {
                dialog.dismiss();
            }
        }

        @Override
        protected void onPreExecute() {

            this.dialog.setMessage("Please wait");
            this.dialog.show();
        }

        @Override
        protected void onProgressUpdate(Void... values) {

        }
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);

//Point 4
        if (resultCode == RESULT_OK) {
            if (data != null) {

                photo = (Bitmap) data.getExtras().get("data");
                userImage.setImageBitmap(photo);

            }else{

                Intent intent = new Intent(UserProfileActivity.this,
                        UserProfileActivity.class);
                startActivity(intent);
            }
        } else {

            Intent intent = new Intent(UserProfileActivity.this,
                    UserProfileActivity.class);
            startActivity(intent);
        }
    }
}
  • 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-09T14:59:50+00:00Added an answer on June 9, 2026 at 2:59 pm

    Camera activity is meant to run in background.

    Hence calling camera using the intent

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, CAMERA_REQUEST);
    

    will call the doInBackground(String… params)

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

Sidebar

Related Questions

My Activity creates an AsyncTask that loads data from a file and updates the
I am setting up a ListView adapter like this: public class SeeAllQuestionsActivity extends Activity
Hi all i'm getting a NPE when setting an ImageView a bitmap. The bitmap
Is it possible to set the font for all the TextViews in a activity?
So i have this activity : public class settings_dock extends Activity { AlertDialog alert;
In activity I load preferences like: public void LoadFontSize(){ sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); loadedFontSize =
I have an Android application with a main activity that is the tabhost. I'm
I have a preferences activity where I can change the language and the theme
I am building one app & this is the setting page(Activity view) of my
I basically would like to load an image from a url to an activity

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.