• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Login

hi friends
i have code for login page, (if i click the login button mean it will need to display the Welcome message and coordintes of GPS in second page,) but it display only the welcome msg doesnt display the coordinates.

second page code is pasted below

help me plz

Code:
package com.example.login2;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.content.Intent;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class login2 extends Activity {
    EditText un, pw;
    TextView error;
    Button ok;
    String text;
    int L4, L5, L3;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        un = (EditText) findViewById(R.id.et_un);
        pw = (EditText) findViewById(R.id.et_pw);
        ok = (Button) findViewById(R.id.btn_login);
        error = (TextView) findViewById(R.id.tv_error);

        ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("UserName", un
                        .getText().toString()));
                postParameters.add(new BasicNameValuePair("Pwd", pw.getText()
                        .toString()));
                // String valid = "1";
                String response = null;
                try {
                    response = CustomHttpClient.executeHttpPost(
                            "http://10.0.2.2/androidapp/index.php",
                            postParameters);
                    String res = response.toString();
                    res = res.trim();
                    if (res.equals("Success")) {

                        Intent i = new Intent(getApplicationContext(),
                                second.class);

                        // Sending data to another Activity
                        i.putExtra("name", un.getText().toString());

                        un.getText();

                        startActivity(i);

                    }

                    else {
                        error.setText(res);
                    }

                    // res= res.replaceAll("\\s+","");

                } catch (Exception e) {
                    un.setText(e.toString());
                }

            }
        });
    
    }
}
 
Second page code;

Code:
package com.example.login2;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class second extends Activity {

    /** Called when the activity is first created. */

    Button login;
    LocationManager locationManager;
    String provider, Test, Vishnu, kamal;
    double L1,L2;
    
    int L3;
    int L4;
    int L5;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);

        TextView txtName = (TextView) findViewById(R.id.txt2);
        Button login = (Button) findViewById(R.id.btn_login);

        Intent i = getIntent();
        // Receiving the Data
        String name = i.getStringExtra("name");

        // Displaying Received data
        txtName.setText("Hai" + " " + name + " " + "Welcome");

    
    if (name.equals("Test")) {

            L3 = 1;
            if(name.equals("Vishnu")) {
                
                L4 = 2;
                if(name.equals("kalam")) {
                    L5 = 3;
                }
            }
            

        }

    }

    class MyLocationListener implements LocationListener {
        @Override
        public void onLocationChanged(Location location1) {

            Criteria criteria = new Criteria();
            provider = locationManager.getBestProvider(criteria, false);
            Location location = locationManager
                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);

            L1 = location.getLatitude();
            L2 = location.getLongitude();
            Toast.makeText(
                    getBaseContext(),
                    "Latitude: " + location.getLatitude() + "Longitude: "
                            + location.getLongitude(), Toast.LENGTH_LONG)
                    .show();

        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }
    }

}
 
Back
Top Bottom