我正在进行Android应用程序开发,目前遇到了困难:
我有两个活动: 第一个名为CurrentLoc,它可以获取我的当前位置,获取位置后,我点击按钮进入第二个名为Sms的活动。
我需要做的是当我点击按钮时,将第一个活动中接收到的位置数据传递给第二个活动...
下面是第一个活动的代码:
我有两个活动: 第一个名为CurrentLoc,它可以获取我的当前位置,获取位置后,我点击按钮进入第二个名为Sms的活动。
我需要做的是当我点击按钮时,将第一个活动中接收到的位置数据传递给第二个活动...
下面是第一个活动的代码:
public class Tester2Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startService(new Intent(Tester2Activity.this,SS.class));
LocationManager mlocManager = (LocationManager)getSystemService (Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
Button button1 = (Button) findViewById(R.id.widget30);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent hg = new Intent(Tester2Activity.this, Sms.class);
startActivity(hg);
}
});
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
//This is what i want to pass to the other activity when i click on the button
}
@Override
public void onProviderDisabled(String provider)
{
}
@Override
public void onProviderEnabled(String provider)
{
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
}