小编Mal*_*lik的帖子

将位置数据传递到Android中的其他活动

我正在进行Android应用程序开发,我陷入了这一点:

我有2个活动:第一个叫做CurrentLoc,它让我获得当前位置,在获得位置后,我点击一个按钮,将我带到2号活动,称为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 …
Run Code Online (Sandbox Code Playgroud)

java android

2
推荐指数
1
解决办法
4898
查看次数

标签 统计

android ×1

java ×1