2013-07-28 78 views
1

如何從延伸Thread類的run()方法使用LOCATION_SERVICE? 這些兩者都是給我的錯誤:使用線程中的LOCATION_SERVICE

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

的方法getSystemService(字符串)是未定義的類型Thread_ReadGps和

lm = (LocationManager) context.getSystemService(LOCATION_SERVICE); 

LOCATION_SERVICE不能被解析爲一個變量

謝謝!

回答

8

getSystemService是一種上下文的方法,因此您需要像在第二行中那樣調用它。

LOCATION_SERVICE也是上下文的靜態變量,因此您需要在第一行中調用它。因此,只需結合你的第一和第二行得到:

lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); 
+0

它現在有道理,謝謝! – user2566468