我怎样才能在Android的登录/注销管理会话? [英] How can I manage session in Android login/logout?

查看:113
本文介绍了我怎样才能在Android的登录/注销管理会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司成功开发一个登录表单。但现在我不能够管理会议......还我已阅读多个会话concepts.but我不能这样做it.please解释我的细节。这是我的code。请帮助我怎么可以在这里使用会话的一部分。

这是我的编码部分:

 包com.androidlogin.ws;

进口org.ksoap2.SoapEnvelope;
进口org.ksoap2.serialization.PropertyInfo;
进口org.ksoap2.serialization.SoapObject;
进口org.ksoap2.serialization.SoapPrimitive;
进口org.ksoap2.serialization.SoapSerializationEnvelope;
进口org.ksoap2.transport.HttpTransportSE;
进口android.app.Activity;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.TextView;

 公共类AndroidLoginExampleActivity延伸活动{
 私人最终字符串NAMESPACE =htt​​p://ws.userlogin.com;
 私人最终字符串URL =htt​​p://111.223.128.10:8085/AndroidLogin/services/Login?wsdl;
私人最终字符串SOAP_ACTION =htt​​p://ws.userlogin.com/authentication;
私人最终字符串METHOD_NAME =认证;
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    按钮的登录=(按钮)findViewById(R.id.btn_login);
    login.setOnClickListener(新View.OnClickListener(){

  公共无效的onClick(查看为arg0){
   在loginAction();

   }
   });
   }

 私人无效则loginAction(){
 SoapObject请求=新SoapObject(命名空间METHOD_NAME);

    EditText上的userName =(EditText上)findViewById(R.id.tf_userName);
    。字符串USER_NAME = userName.getText()的toString();
    EditText上的userPassword =(EditText上)findViewById(R.id.tf_password);
    。字符串USER_PASSWORD = userPassword.getText()的toString();

  Web服务的username变量//传递价值
    的PropertyInfo unameProp =新的PropertyInfo();
    unameProp.setName(username的); //定义在Web服务方法的变量名
    unameProp.setValue(USER_NAME); //设置username变量值
    unameProp.setType(为String.class); //定义变量的类型
    request.addProperty(unameProp); //通行证属性到可变

  Web服务的密码变量//传递价值
    的PropertyInfo passwordProp =新的PropertyInfo();
    passwordProp.setName(密码);
    passwordProp.setValue(USER_PASSWORD);
    passwordProp.setType(为String.class);
    request.addProperty(passwordProp);

    SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(要求);
    HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);

    尝试{
        androidHttpTransport.call(SOAP_ACTION,包);
           SoapPrimitive响应=(SoapPrimitive)envelope.getResponse();

           TextView的结果=(TextView中)findViewById(R.id.tv_status);
           result.setText(response.toString());

    }
    赶上(例外五){

    }
   }

   }
 

解决方案

清除活性栈做的时候退出操作。

 意向意图=新的意图(这一点,LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(意向);
 

然后后退按钮会留在LoginActivity活动以来堆栈被清除。 我想这会帮助你。

i successfully developed one login form. But now I am not able to manage session...also i have read more session concepts.but i can't do it.please explain me in detail. This is my code. Please help how I can use Session part here.

This is my coding part:

package com.androidlogin.ws;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
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 AndroidLoginExampleActivity extends Activity {
 private final String NAMESPACE = "http://ws.userlogin.com";
 private final String URL = "http://111.223.128.10:8085/AndroidLogin/services/Login?wsdl";
private final String SOAP_ACTION = "http://ws.userlogin.com/authentication";
private final String METHOD_NAME = "authentication";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button login = (Button) findViewById(R.id.btn_login);
    login.setOnClickListener(new View.OnClickListener() {

  public void onClick(View arg0) {
   loginAction();

   }
   });
   }

 private void loginAction(){
 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    EditText userName = (EditText) findViewById(R.id.tf_userName);
    String user_Name = userName.getText().toString();
    EditText userPassword = (EditText) findViewById(R.id.tf_password);
    String user_Password = userPassword.getText().toString();

  //Pass value for userName variable of the web service
    PropertyInfo unameProp =new PropertyInfo();
    unameProp.setName("userName");//Define the variable name in the web service method
    unameProp.setValue(user_Name);//set value for userName variable
    unameProp.setType(String.class);//Define the type of the variable
    request.addProperty(unameProp);//Pass properties to the variable

  //Pass value for Password variable of the web service
    PropertyInfo passwordProp =new PropertyInfo();
    passwordProp.setName("password");
    passwordProp.setValue(user_Password);
    passwordProp.setType(String.class);
    request.addProperty(passwordProp);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try{
        androidHttpTransport.call(SOAP_ACTION, envelope);
           SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

           TextView result = (TextView) findViewById(R.id.tv_status);
           result.setText(response.toString());

    }
    catch(Exception e){

    }
   }

   }

解决方案

Clear activity stack when doing logout operation.

Intent intent  = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Then back button will stay at LoginActivity since the activity stack is cleared. I guess it will help you.

这篇关于我怎样才能在Android的登录/注销管理会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆