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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:59:21+00:00 2026-06-12T23:59:21+00:00

I have an activity class setup from a tutorial I found. The activity class

  • 0

I have an activity class setup from a tutorial I found. The activity class simply opens a new screen and displays the message from a textbox on the mainActivity. The APP calls a php file on a server which returns JSON data. That side all works well in the browser when I test it.

Now for the android issue. I am trying to get that data to be shown in the messageActivity class. I have tried to simply use the below code to do it but eclipse flags the intent line saying the “The constructor Intent(Connect, Class) is undefined”

My question is this what is the correct way to fire the activity so that the JSON data will be shown and secondly if you look at the quaryDB method how do I get the JSON data to the messageActivity from the response?

Main Activity:

public class MainActivity extends Activity {
RadioButton radioButton1, radioButton2, radioButton3;

public final static String EXTRA_MESSAGE = "com.example.xxxxxxx.MESSAGE";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    radioButton1 = (RadioButton)findViewById(R.id.radioButton1);
    radioButton2 = (RadioButton)findViewById(R.id.radioButton2);
    radioButton3 = (RadioButton)findViewById(R.id.radioButton3);
    radioButton1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) { 
            if (radioButton1.isChecked()){
                radioButton2.setChecked(false);
                radioButton3.setChecked(false);
            }

        }
    });

    radioButton2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) { 
            if (radioButton2.isChecked()){
                radioButton3.setChecked(false);
                radioButton1.setChecked(false);
            }

        }
    });

    radioButton3.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) { 
            if (radioButton3.isChecked()){
                radioButton2.setChecked(false);
                radioButton1.setChecked(false);
            }

        }
    });



    Spinner spinner = (Spinner) findViewById(R.id.spinner);
 // Create an ArrayAdapter using the string array and a default spinner layout
 ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
         R.array.PracticeTypes, android.R.layout.simple_spinner_item);
 // Specify the layout to use when the list of choices appears
 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 // Apply the adapter to the spinner
 spinner.setAdapter(adapter);
 spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
 Connect c = new Connect();
 c.quaryDB(this);

}


public class MyOnItemSelectedListener implements OnItemSelectedListener{
public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id){
    Toast.makeText(parent.getContext(), "The Selected Practice is " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent){

}
 }
 public void sendMessage(View view){
    Intent intent= new Intent(this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;

}

};

The DisplayMessageActivity:

 public class DisplayMessageActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_message);
   Intent intent = getIntent();
   String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

   TextView textView= new TextView(this);
   textView.setTextSize(40);
   textView.setText(message);

   setContentView(textView);
 }
}

And then the connect class that gets the JSON data response:

 public class Connect{

void Connect(){

}

public void quaryDB(Context context){

    Connection conn=null;
    try{
        HttpClient client = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.0.6/DevServer/getAllByZip.php");
        HttpResponse response = client.execute(httppost);
        HttpEntity entity = response.getEntity();
        String succMsg = "Successful Execute.\n";

        Toast.makeText(context, succMsg, Toast.LENGTH_LONG).show();
    }
    catch (Exception e){
        String errMsg ="Cannot connect to database server.\n"+e.toString();
        Toast.makeText(context, errMsg, Toast.LENGTH_LONG).show();
    }
    finally{
        if (conn !=null){
            try{
                conn.close();
            }
            catch (Exception e){
            }
        }
    }
}
   public void sendMessage(View view){
        Intent intent= new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }   
    }

The sendMessage method doesn’t feel right being in the Connect class but I am lost as to how to properly send the JSON data to the DisplayMessageActivity. After I figure that part out I will be able to begin parsing the data and doing what needs to be done.

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

    Fisrt I’ll explain the issue:

    The constructer for Intent is expecting a activity context as first parameter. When you use it in a class that extends Activity you can use this as first parameter, which is the activity itself.

    When you use it in the class Connect, which doesn’t extend Activity, using this as first parameter reverts to the class Connect wich doesn´t have a context.

    Solution:

    If you are calling sendMessage from the activity, you can do the following:

    in the activity

    sendMessage(this, myview);
    

    in the class Connect

    public void sendMessage(Context context, View view){  
        Intent intent= new Intent(context, DisplayMessageActivity.class);  
        EditText editText = (EditText) findViewById(R.id.edit_message);  
        String message = editText.getText().toString();  
        intent.putExtra(EXTRA_MESSAGE, message);  
        startActivity(intent);  
    } 
    

    If you are not calling it from the activity, pass the context to the class constructer:

    public class Connect{      
    
    Context context;
    void Connect(Context context){      
       this.context = context;  
    }  
    

    and you can now use the context in sendMessage()

    good luck

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

Sidebar

Related Questions

Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
I have 4 buttons that when click starts a new activity class. This works
I have TabActivityGroup: MainActivity class contain some tab, that name loading from db. Sales,
I have an Activity that pulls an object from an Application extended class (application
I have an Activity class which has an attribute that references an AsyncTask instance
I have a non-Activity class (let's call it NonActivity) that needs to post a
So i have this activity : public class settings_dock extends Activity { AlertDialog alert;
I have class A which extends the Activity class. This class is in package
I have a problem to test my non activity-class which need the context of
I have a list of objects called Activity: class Activity { public Date activityDate;

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.