我是安卓新手。我试图从一个活动中得到这个:
i.putExtra("mlat", String.valueOf(latitude));
到这里:
public class PostDataActivity extends AsyncTask<Void, Void, Void>{
GpsData gps;
// double latitude = gps.getLatitude();
//String mlat;
@Override
protected Void doInBackground(Void... params) {
Bundle extras = getIntent().getExtras();
String mlat = extras.getString("mlat");
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://test.de");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("lat", mlat));
nameValuePairs.add(new BasicNameValuePair("lon", "7.358154"));
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
httpClient.execute(httpPost);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
但是 getIntent 是未定义的
Bundle extras = getIntent().getExtras();
String mlat = extras.getString("mlat");
如何在 Activity 和 doInBackground 之间传输数据?