【发布时间】:2019-06-06 15:32:46
【问题描述】:
我正在开发一个 Android 应用程序,但我被困在这一点上:
我有 2 项活动: 第一个叫做 CurrentLoc,它让我获得当前位置,在获得位置后,我点击一个按钮,将我带到名为 Sms 的活动编号 2。
我需要做的是,当我单击按钮时,我想将我在第一个活动中收到的位置数据传递给第二个活动......
这是我第一个活动的代码:
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)
{
}
}
}
【问题讨论】:
-
你的问题解决了吗?