在我的登录活动中......我在询问用户名和密码......我想检查用户是否是授权用户......如果用户被授权,那么我的网络活动 menu.java 开始......否则他应该是重定向到同一个登录页面...带有警报...用户不存在...怎么做?
我已经写了我的活动.. 我怎样才能开始下一个活动?
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login_Menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login_lay);
final TextView tv=(TextView) findViewById(R.id.login_stat_tv);
final EditText uname=(EditText)findViewById(R.id.uname);
final EditText pass=(EditText)findViewById(R.id.pass);
Button login=(Button)findViewById(R.id.login_but);
Button cancel=(Button)findViewById(R.id.cancel_but);
final HttpClient client = new DefaultHttpClient();
String url="http://10.0.2.2:7001/f/json.jsp";
final HttpPost post = new HttpPost(url);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
try{
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("username",uname.getText().toString()));
pairs.add(new BasicNameValuePair("password",pass.getText().toString()));
post.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = null;
while ((line = rd.readLine()) != null) {
tv.append(line);
}
//startActivity(new Intent("com.campuspro.start.DEMO_RETRV"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
cancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
uname.getText().clear();
pass.getText().clear();
}
});
}
}