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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:27:35+00:00 2026-06-09T21:27:35+00:00

Can any one please tell me where to find a simple tutorial that shows

  • 0

Can any one please tell me where to find a simple tutorial that shows how to make an Android application that connects to a external MySQL database, and report back some data?

The tutorials I found on the Internet are not exact – they dont work or the code is not complete.

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import android.widget.Toast;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class main extends Activity {
    /** Called when the activity is first created. */
    Button login;
    String name = "", pass = "";
    EditText username, password;
    TextView tv;
    byte[] data;
    HttpPost httppost;
    StringBuffer buffer;
    HttpResponse response;
    HttpClient httpclient;
    InputStream inputStream;
    SharedPreferences app_preferences;
    List<NameValuePair> nameValuePairs;
    CheckBox check;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
        username = (EditText) findViewById(R.id.username);
        password = (EditText) findViewById(R.id.password);
        login = (Button) findViewById(R.id.login);
        check = (CheckBox) findViewById(R.id.check);

        String Str_user = app_preferences.getString("username", "0");
        String Str_pass = app_preferences.getString("password", "0");
        String Str_check = app_preferences.getString("checked", "no");
        if (Str_check.equals("yes")) {
            username.setText(Str_user);
            password.setText(Str_pass);
            check.setChecked(true);
        }

        login.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                name = username.getText().toString();
                pass = password.getText().toString();
                String Str_check2 = app_preferences.getString("checked", "no");
                if (Str_check2.equals("yes")) {
                    SharedPreferences.Editor editor = app_preferences.edit();
                    editor.putString("username", name);
                    editor.putString("password", pass);
                    editor.commit();
                }
                if (name.equals("") || pass.equals("")) {
                    Toast.makeText(main.this, "Blank Field..Please Enter",
                            Toast.LENGTH_LONG).show();
                } else {
                    try {
                        httpclient = new DefaultHttpClient();
                        httppost = new HttpPost(
                                "http://www.****.com/android/check.php");

                        // Add your data
                        nameValuePairs = new ArrayList<NameValuePair>(2);
                        nameValuePairs.add(new BasicNameValuePair("UserEmail",
                                name.trim()));
                        nameValuePairs.add(new BasicNameValuePair("Password",
                                pass.trim()));
                        httppost.setEntity(new UrlEncodedFormEntity(
                                nameValuePairs));

                        // Execute HTTP Post Request
                        response = httpclient.execute(httppost);
                        inputStream = response.getEntity().getContent();

                        data = new byte[256];

                        buffer = new StringBuffer();
                        int len = 0;
                        while (-1 != (len = inputStream.read(data))) {
                            buffer.append(new String(data, 0, len));
                        }

                        inputStream.close();
                    } catch (Exception e) {
                        Toast.makeText(main.this, "error" + e.toString(),
                                Toast.LENGTH_LONG).show();
                    }

                    if (buffer.charAt(0) == 'Y') {
                        Toast.makeText(main.this, "login successfull",
                                Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(main.this,
                                "Invalid Username or password",
                                Toast.LENGTH_LONG).show();
                    }
                }
            }
        });
        check.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks, depending on whether it's now
                // checked
                SharedPreferences.Editor editor = app_preferences.edit();
                if (((CheckBox) v).isChecked()) {

                    editor.putString("checked", "yes");
                    editor.commit();
                } else {
                    editor.putString("checked", "no");
                    editor.commit();
                }
            }
        });
    }

    public void Move_to_next() {
        // startActivity(new Intent(this, zzz.class));
    }
}
  • 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-09T21:27:37+00:00Added an answer on June 9, 2026 at 9:27 pm

    I couldn’t easily find a fully described example. But heres where i would start.

    1. Look at content providers for managing your app data and accessing it and storing it for local use. The link below gives an extensive explanation of how content providers work. Though you don’t have to use one.

    http://www.satyakomatineni.com/akc/display?url=DisplayNoteIMPURL&reportId=2882&ownerUserId=satya

    The android content provider example also shows this.

    1. On your server at home look at providing a rest full service layer for your app to request the information from. Rather than perhaps trying to directly access the database iteself. Discussed to some extent here on what to do (not specifically how to do it) https://groups.google.com/forum/?fromgroups#!topic/android-developers/rzV9tYpQZ5Y%5B1-25%5D

    Afraid i don’t have coded examples.

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

Sidebar

Related Questions

Can any one please tell me how to set notifications for different values at
Can any one please tell me the difference between target and currenttarget in flex?
can any one please tell me how to get the Google places api key
1)Can Any one please tell me what are the prerequisites have been installed on
Can any one please tell me what are the steps for using JavaBuilder; to
I am new to cocoa development Can any one please tell me how I
Can anyone please tell me how I can write a bash shell script that
Can anyone please tell me how to find the installed SQL Server 2005/2008/2008R2 report
Can anyone please tell/suggest me how can i store and retrieve comments multiple/different values
Can anyone please tell me how to extract this kind of data : [{number:8457215152,type:Cell,state:LA,country:US,tz:CT,zip:70546,msa:0},{number:4363685555,type:Cell,state:LA,country:US,tz:CT,zip:70546,msa:0}]

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.