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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:14:28+00:00 2026-06-11T11:14:28+00:00

This is my first strange result that I never expected. This is may be

  • 0

This is my first strange result that I never expected. This is may be lack of skill in that area.

Well I had a button, through which I need to select an image from the phone gallery (probably from sdcard). I used implicit intent to call the phone gallery and got the absolute image path with startActivityForResult(). Immediately am calling another activity putting that path with startActivity().

According to my scenario I wrote the following code in the onClick() of button.

@Override
public void onClick(View v) {
        upLoadPhoto();
}

protected void upLoadPhoto() {

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
    intent.setType("image/*");
    intent.putExtra("return-data", true);
    System.out.println("select image");
    startActivityForResult(intent, 1);
    startActivity(next);
    finish();
}

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
            if(requestCode == 1 && data != null && data.getData() != null){
                Uri uri = data.getData();
                if (uri != null) {
                    Cursor cursor = getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
                    cursor.moveToFirst();
                    final String imageFilePath = cursor.getString(0);
                    System.out.println("Background : "+imageFilePath);
                    next.putExtra("backImagePath", imageFilePath);
                    cursor.close();
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}

When I click the button, startActivity(next) is called first, then startActivityForResult(intent,1) is called. As am trying to get image path in the second activity through bundle object, am getting NullPointerException because of startActivity(next) is being called first.

I dropped my jaws when I saw my debugging point are not as expected. Hope I get exact reason to this issue.

Thanks
Aswin

  • 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-11T11:14:29+00:00Added an answer on June 11, 2026 at 11:14 am

    What about moving the call to startActivity(next); into onActivityResult()… this way you will navigate to the other activity after getting the path

    protected void upLoadPhoto() {
    
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
    intent.setType("image/*");
    intent.putExtra("return-data", true);
    System.out.println("select image");
    startActivityForResult(intent, 1);
    
    finish();
    

    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
            if(requestCode == 1 && data != null && data.getData() != null){
                Uri uri = data.getData();
                if (uri != null) {
                    Cursor cursor = getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
                    cursor.moveToFirst();
                    final String imageFilePath = cursor.getString(0);
                    System.out.println("Background : "+imageFilePath);
                    next.putExtra("backImagePath", imageFilePath);
                    cursor.close();
    
                startActivity(next);
    
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
    

    }

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

Sidebar

Related Questions

This is pretty strange (admitedly, this is my first attempt with python / sqlite),
This is a strange problem.I init sem and destory it first,then i init it
Could someone explain this (strange) behavior? Why is the length in the first example
I had this code that help me fetch the URL of an actor page
I've met strange error. Im not sure this is bug. However i never met
That's the first time i post on this site. I explain, i have to
I'm currently facing strange problems with Android's font Roboto. At first I had two
I'm running testunit (with machinist) and getting this very strange result when I run
This seems so super strange. I have the following $.when.apply(null, arrayOfDeferredObjects).then(function(result)) { if (1
This first bit works: $my_id = 617; $post_id_7 = get_post($my_id); $title = $post_id_7->post_excerpt; echo

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.