There is a MainActivity in which the map is used:

public class MainActivity extends FragmentActivity { SupportMapFragment mapFragment; GoogleMap map; protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment); map = mapFragment.getMap(); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); map.getUiSettings().setZoomControlsEnabled(true); map.getUiSettings().setCompassEnabled(true); startService(new Intent(this, TrackerService.class)); } } 

How to transfer / use the same mapFragment, only in Service?

  • there is no need to use it in the service. Service should not work with View. You have problems with architecture ... - Vladyslav Matviienko
  • @metalurgus, ok, methods can also be used from the MainActivity? - redL1ne
  • @metalurgus I think, not only should not, but can not - without confused crutches, at least. - pavlofff

1 answer 1

A service is a service for performing background tasks; it does not have access to the UI, at least no legal access. There is no need to send a fragment to the service for this reason.