目录

MapFragment

Class Info

public class MapFragment

Map component that extends the native Fragment component of Android and can be used to add a map to an app in the simplest way. It provides a view of a map to automatically process the necessary lifecycle functions, and can be loaded to the layout file of Activity for use. To automatically initialize the map system and view, call getMapAsync.

The HuaweiMap object must be obtained using getMapAsync(OnMapReadyCallback callback). This class will automatically initialize the map system and view.

Any object obtained from HuaweiMap will be associated with the view. Do not save objects (such as markers) out of the view's lifecycle. Otherwise, memory leaks will occur because the view cannot be released.

Public Constructor Summary

Constructor Name

MapFragment()

Default constructor of MapFragment.

Public Method Summary

Qualifier and Type

Method Name and Description

void

getMapAsync(OnMapReadyCallback callback)

Obtains a HuaweiMap object when the object is ready.

static MapFragment

newInstance()

Creates a MapFragment object with default attributes.

static MapFragment

newInstance(HuaweiMapOptions options)

Creates a MapFragment object based on the specified options parameter.

void

onActivityCreated(Bundle savedInstanceState)

Lifecycle method inherited from Fragment.

void

onAttach(Activity activity)

Lifecycle method inherited from Fragment.

void

onCreate(Bundle savedInstanceState)

Lifecycle method inherited from Fragment.

View

onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Lifecycle method inherited from Fragment.

void

onDestroy()

Lifecycle method inherited from Fragment.

void

onDestroyView()

Lifecycle method inherited from Fragment.

void

onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState)

Lifecycle method inherited from Fragment. This method is called when Fragment is statically loaded in XML mode.

void

onLowMemory()

Lifecycle method inherited from Fragment. This method is called when the memory is insufficient.

void

onPause()

Lifecycle method inherited from Fragment.

void

onResume()

Lifecycle method inherited from Fragment.

void

onSaveInstanceState(Bundle outState)

Lifecycle method inherited from Fragment and called when MapFragment is destroyed unexpectedly. It is used to save the status of a MapFragment object before it is destroyed.

void

onStart()

Lifecycle method inherited from Fragment.

void

onStop()

Lifecycle method inherited from Fragment.

void

setArguments(Bundle args)

Lifecycle method inherited from Fragment and called when data needs to be passed to MapFragment.

Public Methods

[h2]getMapAsync

Method

public void getMapAsync(OnMapReadyCallback callback)

Obtains a HuaweiMap object when the object is ready.

NOTE:
  • This method must be called in the main thread.
  • The callback will be executed in the main thread.
  • In rare cases, the callback is not triggered when the HuaweiMap object is destroyed immediately after being created.
  • The object provided by the callback of HuaweiMap is not null.

Parameters

Name

Description

callback

Callback to be executed when a HuaweiMap object is ready for use.

[h2]newInstance()

Method

public static MapFragment newInstance()

Creates a MapFragment object with default attributes.

Returns

Type

Description

MapFragment

MapFragment object.

[h2]newInstance(HuaweiMapOptions options)

Method

public static MapFragment newInstance(HuaweiMapOptions options)

Creates a MapFragment object based on the specified options parameter.

Parameters

Name

Description

options

Attributes required for creating a MapFragment object.

Returns

Type

Description

MapFragment

MapFragment object.

[h2]onActivityCreated

Method

public void onActivityCreated(Bundle savedInstanceState)

Lifecycle method inherited from Fragment.

Parameters

Name

Description

savedInstanceState

Status to be saved for a MapFragment object.

[h2]onAttach

Method

public void onAttach(Activity activity)

Lifecycle method inherited from Fragment.

Parameters

Name

Description

activity

Activity object bound to MapFragment.

[h2]onCreate

Method

public void onCreate(Bundle savedInstanceState)

Lifecycle method inherited from Fragment.

Parameters

Name

Description

savedInstanceState

Status to be saved for a MapFragment object.

[h2]onCreateView

Method

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Lifecycle method inherited from Fragment.

Parameters

Name

Description

inflater

LayoutInflater object, which is used to search for controls in a layout.

container

Layout container.

savedInstanceState

Status to be saved for a MapFragment object.

Returns

Type

Description

View

View object.

[h2]onDestroy

Method

public void onDestroy()

Lifecycle method inherited from Fragment.

[h2]onDestroyView

Method

public void onDestroyView()

Lifecycle method inherited from Fragment.

[h2]onInflate

Method

public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState)

Lifecycle method inherited from Fragment. This method is called when Fragment is statically loaded in XML mode.

Parameters

Name

Description

activity

Activity object bound to MapFragment.

attrs

Attributes used to create a MapFragment object.

savedInstanceState

Status to be saved for a MapFragment object.

[h2]onLowMemory

Method

public void onLowMemory()

Lifecycle method inherited from Fragment. This method is called when the memory is insufficient.

[h2]onPause

Method

public void onPause()

Lifecycle method inherited from Fragment.

[h2]onResume

Method

public void onResume()

Lifecycle method inherited from Fragment.

[h2]onSaveInstanceState

Method

public void onSaveInstanceState(Bundle outState)

Lifecycle method inherited from Fragment and called when MapFragment is destroyed unexpectedly. It is used to save the status of a MapFragment object before it is destroyed.

Parameters

Name

Description

outState

Status to be saved for a MapFragment object.

[h2]onStart

Method

public void onStart()

Lifecycle method inherited from Fragment.

[h2]onStop

Method

public void onStop()

Lifecycle method inherited from Fragment.

[h2]setArguments

Method

public void setArguments(Bundle args)

Lifecycle method inherited from Fragment and called when data needs to be passed to MapFragment.

Parameters

Name

Description

args

Data to be passed to MapFragment.