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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:44:05+00:00 2026-05-26T22:44:05+00:00

Simple Concept that is not working: I’m trying to connect to the web and

  • 0

Simple Concept that is not working:

I’m trying to connect to the web and retrieve some data with an asynchronous connection. When the connection returns data, I want to switch to another activity. My code ain’t workin’.

I’m assuming that I’ll need to use a callback of some sort but I’m new to Android / Java and have not been able to find out how to do it by Googling. Can someone please have a look and suggest how I can create a callback that starts the intent when the data returns?:

*UPDATE: I found this nice library here http://loopj.com/android-async-http/ which is an alternative (easy) way to connect to the web in the background.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mtmobtest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".MTMobTestActivity" >            
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity
            android:label="MainMenu"
            android:name=".MainMenu" >            
            <intent-filter >
                <action android:name="android.intent.action.MAINMENU" />
                <category android:name="android.intent.category.MAINMENU" />
            </intent-filter>
        </activity>

    </application>

</manifest>

MTMobTestActivity.java

package com.mtmobtest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.Toast;
import android.widget.ViewFlipper;
public class MTMobTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        postData("Sup yall");
        setContentView(R.layout.main);
    }

    public void postData(String toPost) {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.example.com/test.php");
        //This is the data to send
        String myName = "anybody there?"; //any data to send
        try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("action", myName));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        // Execute HTTP Post Request
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String response = httpclient.execute(httppost, responseHandler);
        //This is the response from a php application
        String reverseString = response;

        //ViewFlipper vf = (ViewFlipper) findViewById(R.layout.menu);
        // Set an animation from res/anim: I pick push left in
        //vf.setAnimation(AnimationUtils.loadAnimation(view.getContext(), R.anim.push_left_in));
        //vf.showNext();

        Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();

        } catch (ClientProtocolException e) {
        Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
        // TODO Auto-generated catch block

        } catch (IOException e) {
        Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
        // TODO Auto-generated catch block
        }

        Intent intent = new Intent(this, MainMenu.class);
        startActivity(intent);

        }
}
  • 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-26T22:44:06+00:00Added an answer on May 26, 2026 at 10:44 pm

    Use an AsyncTask for the job and fire the new Activity in the AsyncTasks onPostExecute method call.

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

Sidebar

Related Questions

Simple issue. I'm working on a proof-of-concept for an application with additional database connection,
I've developed some concept code for a project that I will be working on
I am trying to test a proof of concept that I can run a
I'm working on a simple modelling program concept for Android, and I've come into
I'm working on a relatively small proof-of-concept for some line of business stuff with
I know that s3 does not really support the folder concept. Copy/Delete all files
I'm working with a company that produces a web application using struts with Java.
I'm working on a .net system that will both expose and consume web-services with
Such a simple concept but I'm struggling to express it ... apologies in advance
Basically, why the need for two abstractions of a pretty simple concept?

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.