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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:13:00+00:00 2026-06-17T10:13:00+00:00

I am using onActivityResult to get the data from the previous intent and it

  • 0

I am using onActivityResult to get the data from the previous intent and it is work fine.

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
        case (11): {
            newPosition = data.getIntExtra("position", 0);
            break;
        }
        }
    }

But the issue is occur when I use action bar back button to go back to the previous intent. It is giving this following error:

01-10 15:33:34.128: E/AndroidRuntime(642): FATAL EXCEPTION: main
01-10 15:33:34.128: E/AndroidRuntime(642): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=11, result=0, data=null} to activity {com.cogneti/com.cogneti.ui.recall.TestActivity}: java.lang.NullPointerException
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2726)
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.app.ActivityThread.handleSendResult(ActivityThread.java:2769)
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.app.ActivityThread.access$2000(ActivityThread.java:123)
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1023)
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.os.Looper.loop(Looper.java:126)
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.app.ActivityThread.main(ActivityThread.java:3997)
01-10 15:33:34.128: E/AndroidRuntime(642):  at java.lang.reflect.Method.invokeNative(Native Method)
01-10 15:33:34.128: E/AndroidRuntime(642):  at java.lang.reflect.Method.invoke(Method.java:491)
01-10 15:33:34.128: E/AndroidRuntime(642):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-10 15:33:34.128: E/AndroidRuntime(642):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-10 15:33:34.128: E/AndroidRuntime(642):  at dalvik.system.NativeStart.main(Native Method)
01-10 15:33:34.128: E/AndroidRuntime(642): Caused by: java.lang.NullPointerException
01-10 15:33:34.128: E/AndroidRuntime(642):  at com.cogneti.ui.recall.TestActivity.onActivityResult(TestActivity.java:221)
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.app.Activity.dispatchActivityResult(Activity.java:4483)
01-10 15:33:34.128: E/AndroidRuntime(642):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2722)
01-10 15:33:34.128: E/AndroidRuntime(642):  ... 11 more

It is working fine when I use default back button.

I setresult in onBackPressed() method.

@Override
    public void onBackPressed() {
        Intent resultIntent = new Intent();
        resultIntent.putExtra("position", selectedPosition);
        setResult(Activity.RESULT_OK, resultIntent);
        super.onBackPressed();
    }; 
  • 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-17T10:13:01+00:00Added an answer on June 17, 2026 at 10:13 am

    Ok,

    Make a Function of result data with code.

    Intent resultIntent = new Intent();
    resultIntent.putExtra("position", selectedPosition);
    setResult(Activity.RESULT_OK, resultIntent);
    

    And call this function from onStop() or onDestroy() of Previous Activity.

    Actually I think When you press Back from Action Bar public void onBackPressed() is not called, so you have to call this code in onStop() or onDestroy() of activity.

    Update:

    I think this will called when you press back on Action Bar

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
        // Here write your set Result on Intent code..          
        finish();
        return true;
    }
     return super.onOptionsItemSelected(item);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using following code to open Android Contacts @Override public void onCreate(Bundle savedInstanceState)
I'm trying to take a picture from the Camera using intent with onActivityResult but
I have an app that scans a qrcode to get client data using the
I am using the startActivityForResult to get a picture from the android gallery, however
I need to do the following: Get a picture using the camera from Android...
I am using the default camera intent to get the image in my app.
I am using an intent to call camera and onresult to get the captured
I am using this to return a result from the contact picker. protected void
I'm trying to pull data from a QR code via zxing using the following
I am fetching Uri of a image from gallery using Intent intent = new

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.