Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 成功登录后如何继续进行下一个活动?_Android - Fatal编程技术网

Android 成功登录后如何继续进行下一个活动?

Android 成功登录后如何继续进行下一个活动?,android,Android,问题: 我已经成功地将我的应用程序连接到我的服务器,并且我获得了“成功登录”。。。问题是,在连接之后,我无法让我的活动在成功登录后传递到操作。这是我的密码 public class AndroidLogin extends Activity implements OnClickListener { Button ok,back,exit; TextView result; /** Called when the activity is first created.

问题: 我已经成功地将我的应用程序连接到我的服务器,并且我获得了“成功登录”。。。问题是,在连接之后,我无法让我的活动在成功登录后传递到操作。这是我的密码

public class AndroidLogin extends Activity implements OnClickListener {


    Button ok,back,exit;
    TextView result;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Login button clicked
        ok = (Button)findViewById(R.id.btn_login);
        ok.setOnClickListener(this);

        result = (TextView)findViewById(R.id.lbl_result);

    }

    public void postLoginData() {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();


        HttpPost httppost = new HttpPost("http://www.xxxx.com/login.php");

        try {
            // Add user name and password
            EditText uname = (EditText)findViewById(R.id.txt_username);
            String username = uname.getText().toString();

            EditText pword = (EditText)findViewById(R.id.txt_password);
            String password = pword.getText().toString();

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username", username));
            nameValuePairs.add(new BasicNameValuePair("password", password));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            Log.w("KASIRIS", "Execute HTTP Post Request");
            HttpResponse response = httpclient.execute(httppost);

            String str = inputStreamToString(response.getEntity().getContent()).toString();
            Log.w("KASIRIS", str);

            if(str.toString().equalsIgnoreCase("true"))
            //  startActivity(new Intent("com.sencide.OK"));
            {
                Log.w("KASIRIS", "TRUE");
                result.setText("Login successful");   
                Intent intent=new Intent(getApplicationContext(),Ok.class);
                startActivity(intent);
                finish();


            }else
            {
                Log.w("KASIRIS", "FALSE");
            //  finish();
                result.setText(str);  

            }

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 

    private StringBuilder inputStreamToString(InputStream is) {
        String line = "";
        StringBuilder total = new StringBuilder();
        // Wrap a BufferedReader around the InputStream
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        // Read response until the end
        try {
            while ((line = rd.readLine()) != null) { 
                total.append(line); 
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Return full string
        return total;
    }

    public void onClick(View view) {
        if(view == ok){
            postLoginData();

        }
           //start new Activity
    }

}
公共类AndroidLogin扩展活动实现OnClickListener{
按钮ok,后退,退出;
文本视图结果;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//单击登录按钮
ok=(按钮)findViewById(R.id.btn\u登录);
好的,setOnClickListener(这个);
结果=(TextView)findViewById(R.id.lbl_结果);
}
public void postloginanda(){
//创建一个新的HttpClient和Post头
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://www.xxxx.com/login.php");
试一试{
//添加用户名和密码
EditText uname=(EditText)findViewById(R.id.txt_用户名);
字符串username=uname.getText().toString();
EditText pword=(EditText)findViewById(R.id.txt_密码);
字符串密码=pword.getText().toString();
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“用户名”,username));
添加(新的BasicNameValuePair(“密码”,password));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
w(“KASIRIS”,“执行HTTP Post请求”);
HttpResponse response=httpclient.execute(httppost);
字符串str=inputStreamToString(response.getEntity().getContent()).toString();
Log.w(“KASIRIS”,str);
if(str.toString().equalsIgnoreCase(“true”))
//startActivity(新意图(“com.sencide.OK”);
{
Log.w(“KASIRIS”,“TRUE”);
result.setText(“登录成功”);
Intent Intent=新的Intent(getApplicationContext(),Ok.class);
星触觉(意向);
完成();
}否则
{
Log.w(“KASIRIS”、“FALSE”);
//完成();
结果:setText(str);
}
}捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
} 
私有StringBuilder inputStreamToString(InputStream为){
字符串行=”;
StringBuilder总计=新StringBuilder();
//在InputStream周围包装一个BufferedReader
BufferedReader rd=新的BufferedReader(新的InputStreamReader(is));
//读取响应直到结束
试一试{
而((line=rd.readLine())!=null){
合计.追加(行);
}
}捕获(IOE异常){
e、 printStackTrace();
}
//返回完整字符串
返回总数;
}
公共void onClick(视图){
如果(视图==ok){
postloginanda();
}
//开始新的活动
}
}

在哪里可以获得“成功登录”?这不是实现的方法:首先执行一个新线程来发出web请求(或使用处理程序),然后向处理程序发布一个runnable,使您能够与视图通信。Marcus。。。您的权利,我没有收到一个成功的登录服务器,但当我尝试从桌面浏览器http我可以登录没有问题。。。现在我不知道为什么adroid没有从device.AsTeR读取我的用户信息。。。我想做的是让用户登录(将该信息保存到服务器,然后用户继续进行下一个活动或应用程序销毁)或注册。它可能是服务器端,但我不知道为什么??