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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:55:44+00:00 2026-05-24T17:55:44+00:00

When using Android startActivityForResult , I don’t have any guarantee about what I’ll get

  • 0

When using Android startActivityForResult, I don’t have any guarantee about what I’ll get in the Intent returned by onActivityResult.

I would like to define some kind of interface to limit the possibility of errors when transmitting data from an Activity to another (eg mistyped variable name).

Is there a way to do that? For example could I use something similar to the Android Interface Definition Language but between Activitys?

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

    There are 2 scenarios when passing data between two activities A,B.

    1. Activity A wants to pass data on Activity B ( through the startActivity Intent )
    2. Activity B wants to return data on Activity A when it ends using setResult

    on both cases i suggest to create some public static final variables for the extra keys to use.

    For example if you need to pass an integer using the key “rating” from A to B i would probably do

    class A extends Activity {
        public static final String RESULT_STATUS = "RESULT_STATUS";
        // Whatever ....
        public void startB(int rating) { 
            Intent toStart = new Intent(this, B.class);
            toStart.putExtra(B.EXTRA_RATING, rating);
            startActivityForResult(toStart, 0);
        }
    
        public void onActivityResult(int requestCode /* 0 in our case */, int resultCode, Intent data) {
                if (resultCode == RESULT_OK ) {
                        String returnedStatus = data.getStringExtra(RESULT_STATUS);
                        // Whatever ....
                }
    
    }
    
    class B extends Activity {
        public static final String EXTRA_RATING = "EXTRA_RATING";
        public void onCreate(Bundle b) {
            // Whatever ....
            int rating = getIntent().getIntExtra(EXTRA_RATING,0);
        }
    
        // Whatever ....
    
        public void returnDataAndFinish(String status) {
            Intent result = new Intent();
            result.putExtra(A.RESULT_STATUS, status);
            setResult(RESULT_OK, result);
            finish();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the startActivityForResult to get a picture from the android gallery, however
I am using intent to launch camera: Intent cameraIntent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE); getParent().startActivityForResult(cameraIntent,
I am trying to get away from using 5 buttons when I would like
I am opening android camera using intent like this : Intent cameraIntent = new
I'm making a popup in Android using Toast, is there any way when shown
I made an android project using eclipse. It looks like: src/ ActivityMain.java lib/ Square.java
Well, in my application I'm using default camera and gallery of Android with startActivityforResult
I'm using eclipse, and I have two android projects which have different topics. And
In My Android Camera Application, I am using this code to get Select Image
I have a question about parcelable class (android). Until now, I have passed a

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.