GPS.javaというサービスにバインドされているmessage.javaというアクティビティがあります。 GPS.javaから取得した緯度と経度は、message.javaで使用する必要があります。 servicebinderを使用して、onServiceConnected()で緯度と経度のデフォルト値を取得しています。 ここmessage.javaサービス完了時にアクティビティを通知するにはどうすればよいですか?
`Intent i=new Intent(getApplicationContext(), GPS.class);
bindService(i,mConnection,Context.BIND_AUTO_CREATE)
private GPS servicebinder;
ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
servicebinder = ((GPS.MyBinder)service).getService();
double lat=servicebinder.getlatitude();
double lon=servicebinder.getlongitude();
tex.setText("\nlatitude: " + lat+ "\nlongitude: "
+ lon);
// do any extra setup that requires your Service
}
getLatitude()とgetLongitude()正しいGPS.javaに見出さ緯度と経度を返すためのコードです。問題は上記のlatとlonがデフォルト値を表示しているので、サービスの緯度と経度が更新されたらlatとlonも更新する必要があります(サービスの更新時にアクティビティに通知する必要があります)
適切