I'm creating an app that interacts with SOAP web-services to get data from the database. When the user successfully logins in by passing the username and password via web-services , a unique session ID to that user is given. This session ID will be needed later on in other activities to call web-services methods. My question is, how can I pass on that session ID to the next activity when its needed and maintain it until the user logs out. For example: This is a web-service method, that requires the SID(session id) to be passed on, how can i take that session ID that was giving to me when i logged in, and use it for this method
-<element name="createAttachment">
-<complexType>
-<sequence>
<element name="sid" type="xsd:int"/>
<element name="repositoryHandle" type="xsd:string"/>
<element name="objectHandle" type="xsd:string"/>
<element name="description" type="xsd:string"/>
<element name="fileName" type="xsd:string"/>
</sequence>
</complexType>
</element>
Thats my login.java . I can login successfully and i get a session id
public class Login extends ActionBarActivity implements OnClickListener {
private static final String NAMESPACE = "***";
private static final String URL = ***";
private static final String METHOD_NAME = "login";
private static final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME; //in wsdl it's nothing
EditText usersusername, userspassword;
Button LB;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
LB = (Button) findViewById(R.id.loginbutton);
LB.setOnClickListener(this);
usersusername = (EditText)findViewById(R.id.editusername);
userspassword = (EditText)findViewById(R.id.editpassword);
}
public void onClick(View view){
switch (view.getId()){
case R.id.loginbutton:
new LongOperation().execute("");
break;
}
}
private class LongOperation extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
usersusername = (EditText)findViewById(R.id.editusername);
userspassword = (EditText)findViewById(R.id.editpassword);
String user_Name = usersusername.getText().toString();
String user_Password = userspassword.getText().toString();
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("username",user_Name);//Pass properties to the variable
PropertyInfo passwordProp =new PropertyInfo();
passwordProp.setName("password");
passwordProp.setValue(user_Password);
passwordProp.setType(String.class);
request.addProperty(passwordProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // Declare the version of the soap request
envelope.setOutputSoapObject(request);
try {
HttpTransportSE aht = new HttpTransportSE(URL);
aht.call(SOAP_ACTION, envelope); //this is the actual part that calls the web service
SoapPrimitive result =(SoapPrimitive)envelope.getResponse();
String Something = result.toString(); // Result string
System.out.println(Something);
if (!TextUtils.isEmpty(Something))
{
Intent intent = new Intent(Login.this,Dashboard.class);
intent.putExtra("username",usersusername.getText().toString());
startActivity(intent);
}
}
catch (Exception e){
e.printStackTrace();
}
return null;
} // closing bracket of do in background
@Override
// show dialog and prepare the fields for retry
}
}
} // closing bracket of long operation
}