2012-11-11 1 views
0

저는 최종 프로젝트를 진행 중이며 Android에 익숙하지 않습니다. LocationManager에서 Activity로 속도를 전달하고 싶습니다. 의도와 함께 전달하려했습니다. 뜻 (Intent j = new Intent(this, CallblockingActivity.class))하지만 작동하지 않습니다. 제발 도와주세요.LocationManager에서 작업으로 속도를 전달하는 방법은 무엇입니까?

public class ShowLocationActivity extends Activity { 
    private TextView latituteField; 
    private TextView longitudeField; 
    private TextView speed; 
    public float a; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.locationmanager); 
     latituteField = (TextView) findViewById(R.id.TextView02); 
     longitudeField = (TextView) findViewById(R.id.TextView04); 
     speed = (TextView)findViewById(R.id.textspeed); 
     LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     LocationListener ll = new mylocationlistener(); 
     lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll); 
    } 


    private class mylocationlistener implements LocationListener { 
     @Override 
     public void onLocationChanged(Location location) { 
      if (location != null) { 
       float lat = (float) (location.getLatitude()); 
       float lng = (float) (location.getLongitude()); 
       latituteField.setText(String.valueOf(lat)); 
       longitudeField.setText(String.valueOf(lng)); 
       a=location.getSpeed(); 
       speed.setText("current speed" + a); 

       *** **My problwm is here,I just want to pass a** 


       Log.d("LOCATION CHANGED", location.getLatitude() + ""); 
       Log.d("LOCATION CHANGED", location.getLongitude() + ""); 
       Toast.makeText(ShowLocationActivity.this, 
         location.getLatitude() + "" + location.getLongitude(), 
         Toast.LENGTH_LONG).show(); 
      } 
     } 
     @Override 
     public void onProviderDisabled(String provider) { 
     } 
     @Override 
     public void onProviderEnabled(String provider) { 
     } 
     @Override 
     public void onStatusChanged(String provider, int status, Bundle extras) { 
     } 
    } 
} 

답변

1

단순히 Intent#putExtra() 사용

Intent intent = getIntent(); 
float speed = intent.getFloatExtra("Speed", 0); // 0 is the default case 
:
Intent j = new Intent(ShowLocationActivity.this, CallblockingActivity.class); 
j.putExtra("Speed", a); 
startActivity(j); 

그리고 새로운 활동에

는 함께 읽기 속도