我有娄代码,我需要的值传递onPostExecute
到另一个intent
,但它让我crash
。 下面是Logins.class
,我需要的值传递onPostExecute
到MainActivity.class
:
public class Logins extends Activity {
String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "Login";
String SOAP_ACTION = "http://tempuri.org/Login";
String URL = "http://test.com/MobileWebService/Related.asmx";
public String Webresponse = "IS NULL ?";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyLogin task = new MyLogin();
task.execute(new String[] { URL });
}
public String[] test(String user,String pass)
{
String[] stvalue = {user,pass};
new MyLogin().execute(stvalue);
return stvalue;
}
private class MyLogin extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... urls) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username", urls[0]);
request.addProperty("pass", urls[1]);
request.addProperty("device", "0");
request.addProperty("security", 128110);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setAddAdornments(false);
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
HttpTransportSE conn = new HttpTransportSE(URL);
conn.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
try {
conn.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope
.getResponse();
Webresponse = response.toString();
Log.i("LOG", Webresponse);
}
catch (Exception e) {
e.printStackTrace();
Log.i("xxx", e.toString());
}
return Webresponse;
}
@Override
protected void onPostExecute(String result) {
// someMethod(result);
Intent intent = new Intent(Logins.this, MainActivity.class);
intent.putExtra("EXTRA_SESSION_ID", result);
startActivity(intent);
}
}
}
这里是我的Activity.class
:
public class MainActivity extends Activity {
EditText UserName;
EditText PassWord;
Button Login;
String mUserName;
String mPassWord;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UserName = (EditText) findViewById(R.id.edtUserName);
PassWord = (EditText) findViewById(R.id.edtPasswprd);
Login = (Button) findViewById(R.id.btnLogin);
Login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mUserName = UserName.getText().toString().trim();
mPassWord = PassWord.getText().toString().trim();
if (mUserName.length() > 0 && mPassWord.length() > 0) {
Logins lt = new Logins();
lt.test(mUserName, mPassWord);
---I need get value from here--->Bundle bundle = getIntent().getExtras();---BUT CRASH----
String uId = bundle.getString("EXTRA_SESSION_ID");
Log.i("OK", uId);
} else {
Toast.makeText(
G.context,
G.context.getResources().getString(
R.string.btn_LoginError), Toast.LENGTH_LONG)
.show();
}
}
});
}
}
我LogCat
是:
AndroidRuntime
at com.test.MainActivity$1.onClick(MainActivity.java:53)