引用下面的代碼..我得到了一個類LocationService,並有一個可變的緯度。我想在另一個類Post中使用該變量。我怎麼做。 基本上我想獲得我在其他課程中從那裏獲得的經度和緯度..因爲我想將它發佈在服務器上。 那我該怎麼做。在另一個類中使用變量
LocationService.java
public class LocationService extends Service{
Context context;
WakeLock wl;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
wl.acquire();
context = this;
final String who = intent.getStringExtra("who");
final LocationManager locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
final LocationListener listener = new LocationListener(){
// start location changed
public void onLocationChanged(Location loc) {
double latitude = loc.getLatitude();
double longitude = loc.getLongitude();
......
......
}
Post.java
public class Post extends LocationService {
}
EDITED Post.java
public class Post extends LocationService {{
super.latitude = loc.getLatitude();
}
}
這將讓我從LocationService類緯Post類..?
你如何使用Post類?它是另一種不同的服務? – zapl 2012-04-24 10:14:32
呀!一個不同的服務..我想從班級LocationService獲得緯度和經度到班級Post,然後在課堂上幫助我發佈服務器上的緯度和經度 – 2012-04-24 10:16:44
將'緯度和經度'變量放在'LocationListener'之外並使它們成爲'LocationService'類的直接成員。也就是說,把它們放在你聲明'context'和'wl'的地方 – 2012-04-24 10:16:47