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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:11:21+00:00 2026-06-11T12:11:21+00:00

I have an activity SearchActivity which extends SherlockActivity. In this activity I have an

  • 0

I have an activity “SearchActivity” which extends SherlockActivity. In this activity I have an options menu which has a search bar and a “Go” button. The data that is entered in the search bar has to be passed to the previous activity “NavigationActivity” which extends SherlockMapActivity.

This is a part of my code of SearchActivity:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

        case R.id.go:
           Intent intent = new Intent();
           intent.putExtra("SearchText", enteredText);
           setResult(200, intent);
           startActivityForResult(intent, 100);
           finish();
           break;

    }
    return true;
}

This is the onActivityResult() method in NavigationActivity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    System.out.println("In onActivityResult method");
    if(data != null && resultCode == 200 && requestCode == 100) {
        String text = data.getStringExtra("SearchText");
        System.out.println("The data is: " + text);
        Toast.makeText(this, "The text entered in the search bar is: " + text, Toast.LENGTH_LONG).show();
    }       
}

The problem is that the onActivityResult() method is never getting called in the NavigationActivity. On pressing the “Go” button I’m able to navigate from the SearchActivity to the NavigationActivity but not able to get the get the data in the NavigationActivity. Could you please help me in this aspect?

Thank you.

  • 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-11T12:11:22+00:00Added an answer on June 11, 2026 at 12:11 pm

    Please see the sample code below and modify your code accordingly.

    Navigation Activity

    public class NavigationActivity extends Activity {
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.navigationActivity);
    
        Button btnTest = (Button) findViewById(R.id.button1);
        btn1.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) 
                        {
              Intent intent = new Intent(Launcher.this,Activity2.class);
              startActivityForResult(intent, 100);
            }
    
        });
    
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
        {
        super.onActivityResult(requestCode, resultCode, data);
    
        if(resultCode ==  200)
        {
    
            String enteredText = "no action defined for this requestcode :"+resultCode;
            if(requestCode == 100)
            {
                enteredText = (String)data.getStringExtra("SearchText");
    
            }
            Toast.makeText(Launcher.this,enteredText,Toast.LENGTH_SHORT).show();
        }
        else
        {
            Toast.makeText(Launcher.this,"some exception occurred",Toast.LENGTH_SHORT).show();
        }
    }
    }
    

    SEARCH ACTIVITY

    public class SearchActivity extends Activity{
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
    
        Button btnGO = (Button)findViewById(R.id.buttonGo);
        btnGO .setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                EditText edtSearchBar = (EditText )findViewById(R.id.tvTest);
    
                   intent.putExtra("SearchText", edtSearchBar .getText().toString());
    
                setResult(200,intent);
                finish();
    
            }
        });
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's have activity A and button in that activity, which opens activity A again.
I have an app that has a list as its main activity and then
I Have activity that get some data from the internet, and shows it to
I have activity A that starts activity B which starts activity C: A ->
I have three tabs that each has its own Activity. The tabs are as
I have an activity handling search ( ACTIVITY_1 ), which works perfectly when I
I have Activity with some data displayed in WebView that I load with WebView#loadDataWithBaseURL
I have an activity that has a TabHost containing a set of TabSpecs each
I have an activity which extends PreferenceActivity. I'm loading preferences from the xml file.
I have activity that parses XML feed (with news) and loads parsed data (text

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.