I've been trying to get a Location Manager to work for a few hours now inside my Fragment.
I found a StackOverflow question about a similar problem, and tried to implement the solution.
The answer is located here: https://stackoverflow.com/a/18533440/3035598
So i almost literally copied everything the answer said, but it is not working for me.
When the map opens I get the error "Google Play Services Missing". This is caused by a NullPointerException as you can read in the answer.
I have no idea why it is not working, since I did everything he said.
Does anyone know what's going wrong?
If I have to provide my code, let me know and I will do that, but it is almost the same as in the link I provided.
EDIT:
The Code I use:
package com.example.bt6_aedapp;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.LatLng;
public class fragmentB extends Fragment implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener {
private GoogleMap map;
private LatLng latlng;
private LocationRequest lr;
private LocationClient lc;
MapFragment mapFragment;
ImageView iv;
private static View view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if(view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if(parent != null) {
parent.removeView(view);
}
}
try {
view = inflater.inflate(R.layout.fragment_b, container, false);
mapFragment = ((MapFragment) this.getActivity().getFragmentManager().findFragmentById(R.id.map));
iv = (ImageView) view.findViewById(R.id.iv);
map = mapFragment.getMap();
map.getUiSettings().setAllGesturesEnabled(false);
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
map.getUiSettings().setZoomControlsEnabled(false);
MapsInitializer.initialize(this.getActivity());
}
catch (InflateException e) {
Toast.makeText(getActivity(), "Problems inflating the view !", Toast.LENGTH_LONG).show();
}
catch (NullPointerException e) {
Toast.makeText(getActivity(), "Google Play Services missing !", Toast.LENGTH_LONG).show();
}
return view;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lr = LocationRequest.create();
lr.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
lc = new LocationClient(this.getActivity().getApplicationContext(),
this, this);
lc.connect();
}
#Override
public void onLocationChanged(Location location) {
latlng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latlng, 10);
map.animateCamera(cameraUpdate);
}
#Override
public void onConnectionFailed(ConnectionResult arg0) {
}
#Override
public void onConnected(Bundle connectionHint) {
lc.requestLocationUpdates(lr, this);
}
#Override
public void onDisconnected() {
}
}
The error I'm getting now is located at row 115:
java.lang.NullPointerException
at com.example.bt6_aedapp.fragmentB.onLocationChanged(fragmentB.java:155)
I checked the location.getLatitude() and location.getLongitude() and both of them are NOT empty, they return a correct value.
Alright, so after a lot of debugging and research, I've found the solution.
All I had to do was replace
`mapFragment = ((MapFragment) this.getActivity().getFragmentManager().findFragmentById(R.id.map));`
with:
mapFragment = ((SupportMapFragment)getFragmentManager().findFragmentById(R.id.map));
Related
so i am making a password manager app for android and i have 1 activity and fragments im using room for sql and all of that works fine but when i rotate the screen the app crashes and im not sure why, it says that it cant find the constructor on the configuration change but if that was the case why would it work in the first place :(
the fragment code
package app.web.fragments.passwords;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import com.google.firebase.analytics.FirebaseAnalytics;
import app.web.R;
import app.web.room_password.Password;
import app.web.view_model.PasswordViewModel;
public class Password_Add_Fragment extends Fragment {
private EditText username, password;
// priority is number picker
private NumberPicker numberPicker;
private Button insert, yeetAll;
private PasswordViewModel passwordViewModel;
private FirebaseAnalytics firebaseAnalytics;
public Password_Add_Fragment(FirebaseAnalytics firebaseAnalytics){
this.firebaseAnalytics = firebaseAnalytics;
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
if (container==null){
return null;
}
View view = inflater.inflate(R.layout.fragment_all_passwords_by_category, container, false);
setButtons(view);
return view;
}
private void setButtons(View view) {
passwordViewModel = new ViewModelProvider(getActivity()).get(PasswordViewModel.class);
username = view.findViewById(R.id.edit_text_add_username);
password = view.findViewById(R.id.edit_text_add_password);
numberPicker = view.findViewById(R.id.number_picker_priority_password);
numberPicker.setMinValue(1);
numberPicker.setMaxValue(100);
insert = view.findViewById(R.id.btn_password_save);
insert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(getContext(), "Insert", Toast.LENGTH_SHORT).show();
String usernameP = username.getText().toString().trim();
String passwordP = password.getText().toString().trim();
int x = numberPicker.getValue();
if (!usernameP.isEmpty() && !passwordP.isEmpty() && x >= 1){
Password passwordX = new Password(usernameP,passwordP,x);
passwordViewModel.insert(passwordX);
Toast.makeText(getContext(), "Saved", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "Cant be empty", Toast.LENGTH_SHORT).show();
}
}
});
yeetAll = view.findViewById(R.id.btn_password_delete_all);
yeetAll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
passwordViewModel.deleteAllPasswords();
Toast.makeText(getContext(), "Deleted All", Toast.LENGTH_SHORT).show();
}
});
}
}
the crash log
Full crash log
nevermind the fix was to just have an empty constructor in the fragment class.
When I write the Code like this, the ControlFragment works fine, but when I use the exact same Code in my other Fragment named "AndresFragment" (second code), it's not working. It says "Default constructor in android.app.Fragment is deprecated". I really don't get it... Can someone please help me, I'm new in
package com.example.fragm;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
public class ControlFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (savedInstanceState != null) {
}
View myView = inflater.inflate(R.layout.controlfragment,
container, false);
return myView;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}
Code for "AndresFragment":
package com.example.fragm;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class AndresFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (savedInstanceState != null) {
// restore internal values if necessary
}
View myView1 = inflater.inflate(R.layout.andresfragment,
container, false);
return myView1;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}
That's my Mainactivity.java with the ControlFragment it works:
package com.example.fragm;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
return;
}
ControlFragment myFragment = new ControlFragment();
getSupportFragmentManager().beginTransaction().add(R.id.my_fragment_container, myFragment).commit();
}
}
But I can't use "AndresFragment"
package com.example.fragm;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
return;
}
AndresFragment myFragment = new AndresFragment();
getSupportFragmentManager().beginTransaction().add(R.id.my_fragment_container, myFragment).commit();
}
}
When I try to compile it, the error is: "error: no suitable method found for add(int,AndresFragment)
getSupportFragmentManager().beginTransaction().add(R.id.my_fragment_container, myFragment).commit();"
You have wrong import in your AndresFragment.
Instead of:
import android.app.Fragment;
You should use:
import androidx.fragment.app.Fragment;
In your first file you have proper import and that is why you don't have error there, android.app.Fragment is old and deprecated so that is why you receive error message since you should be using new one.
If you are getting this:
just invalidate caches and restart
I'm writing a simple program in which a two fragments and one activity is used. Both Fragments are displayed (one at a time) within the activity's Frame Layout. The first fragment is a listview that lists items from which the user can select, then the main activity should swap the first fragment with a detail fragment according to the item position determined by a listener within the first fragment. Trouble is, my program won't actually commence the swap. Here's the code for the activity:
package com.example.user.monkeys;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
public class ListActivity extends FragmentActivity implements
monkeyListFragment.OnMonkeySelectedListener {
#Override
public void onCreate(Bundle savedInstanceState) {
Log.i("Activity", "onCreate Pre-Fragment 1");
super.onCreate(savedInstanceState);
setContentView(R.layout.monkey_list_frame);
if (findViewById(R.id.fragment_container) != null) {
if (savedInstanceState != null) {
return;
}
monkeyListFragment monkeyList = new monkeyListFragment();
monkeyList.setArguments(getIntent().getExtras());
// Add the fragment to the container
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, monkeyList);
Log.i("Activity", "made it end onCreate");
}
}
#Override
public void onMonkeyItemSelected(int position) {
Log.i("From Activity", "onMonkeyItemSelected");
monkeyDetailsFragment newDetailFrag = new monkeyDetailsFragment();
Bundle args = new Bundle();
args.putInt("itemPosition", position);
newDetailFrag.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, newDetailFrag);
transaction.addToBackStack(null);
transaction.commit();
}
}
And the code for the listview fragment:
package com.example.user.monkeys;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class monkeyListFragment extends Fragment{
OnMonkeySelectedListener monkeyCallBack;
private ListView monkeyLV;
private String[] monkeyStrings;
public interface OnMonkeySelectedListener {
public void onMonkeyItemSelected(int position);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.i("Fragment 1", "Made it to onCreateView");
View view = inflater.inflate(R.layout.list_fragment, container, false);
monkeyLV = (ListView) view.findViewById(R.id.monkeyListView);
monkeyStrings = getResources().getStringArray(R.array.monkey_data_list);
ArrayAdapter<String> objAdapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_list_item_1, monkeyStrings);
monkeyLV.setAdapter(objAdapter);
AdapterView.OnItemClickListener monkeyListen = new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i("ListFragment-ClckLstnr", "Made it");
monkeyCallBack.onMonkeyItemSelected(position);
}
};
Log.i("Fragment 1", "Made it past OnItemClick Listener");
return view;
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
monkeyCallBack = (OnMonkeySelectedListener) activity;
}
catch (ClassCastException e) {
throw new ClassCastException(activity.toString());
}
}
}
and finally the code for the detail fragment (this isn't fully fleshed out but it should still swap I believe).
package com.example.user.monkeys;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class monkeyDetailsFragment extends Fragment {
ImageView monkeyPicture;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup
container, #Nullable Bundle savedInstanceState) {
Log.i("From Detail Fragment", "Got here");
View view = inflater.inflate(R.layout.monkey_detail_fragment, container,
false);
return view;
}
}
I found your missing line of code for the listview fragment:
monkeyLV.setOnItemClickListener(monkeyListen)
I have two fragments and one activity.
DataFragment passes info succesfuly to MainActivity and that's why there is no point providing you the code of it. My issue is , that bundle isn't effective on MyMapFragment which extends SupportMapFragment when I am trying to pass data from MainActivity. Of course I've searched a lot for many days but the only solutions given are for a fragment and not for SupportMapFragment which I think it's different.
MainActivity
package com.manuelpap.mapapp;
import android.app.Fragment;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.os.Handler;
import com.google.android.gms.maps.SupportMapFragment;
import com.parse.Parse;
public class MainActivity extends AppCompatActivity {
public String mapLocation="EMPTY";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
Intent intent = getIntent();
if (getIntent().getExtras() != null) {
mapLocation = intent.getExtras().getString("mapLocation");
Bundle bundle=new Bundle();
bundle.putString("message", "From Activity");
MyMapFragment fragobj=new MyMapFragment();
fragobj.setArguments(bundle);
Log.d("MAPLOCATION", "----MainActivity---- " + mapLocation);
finish(); //I am using this because on DataFragment it's starting again , so I don't need multiple instances of MainActivity
}
}
public class MyAdapter extends FragmentPagerAdapter{
public MyAdapter(FragmentManager fm) {
super(fm);
}
#Override
public android.support.v4.app.Fragment getItem(int i){
if(i==0){
return new DataFragment();
}
else {
return new MyMapFragment();
}
}
#Override
public int getCount(){
return 2; //posa scrolls dexia (pages) theloume
}
#Override
public CharSequence getPageTitle(int position) {
if(position==0){
return "DATA";
}
else {
return "MAP";
}
}
}
}
MyMapFragment
package com.manuelpap.mapapp;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.os.Handler;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MyMapFragment extends SupportMapFragment { //kanei extend thn hdh uparxousa class gia to maps ths google alla den mpoorume na thn doume giati einai kleidomenh
public String location="EMPTY";
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Handler handler=new Handler();
handler.post(new Runnable() {
#Override
public void run() {
if (getArguments() == null)
location = "------NOTHING RECIEVED------";
else
location =getArguments().getString("message");
Log.d("MAPFRAGMENTLOCATION", location);
handler.postDelayed(this, 200); // set time here to refresh textView
}
});
GoogleMap googleMap = getMap();
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(new LatLng(40.416775, -3.70379));
googleMap.addMarker(markerOptions);
}
}
It looks like you are finishing your main activity
//I am using this because on DataFragment it's starting again , so I don't need multiple instances of MainActivity
Your DataFragment is in the viewpager so it is supposed to start along with your map fragment. You are not starting multiple instances of main activity that I can see here.
When you call finish() on your main activity that means that the map and pager and everything goes away. Not sure what exactly your looking for but I assume you are trying to pass the location string to the map so I have tailored my answer to fit that use case.
The problem is that you are using new MyMapFragment() without the bundle in the view pager. The other logic that you have in MainActivity pertaining to the Map fragment is not going anything to the one that is displayed with the view pager. Essentially you are just creating another instance of the map fragment that is not displayed anywhere. The view pager is the class that needs the data passed to it.
I thought this link might be helpful here to explain the newInstance Method.
Creating a Fragment: constructor vs newInstance()
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
if (getIntent().getExtras() != null) {
mapLocation = intent.getExtras().getString("mapLocation");
}
viewPager.setAdapter(new MyAdapter(getSupportFragmentManager(), mapLocation));
}
public class MyAdapter extends FragmentPagerAdapter{
private String mMapLocation;
public MyAdapter(FragmentManager fm, String mapLocation) {
super(fm);
mMapLoaction = mapLocation;
}
#Override
public android.support.v4.app.Fragment getItem(int i){
if(i==0){
return new DataFragment();
}
else {
Bundle bndl = new Bundle();
if(!TextUtils.isEmpty(mapLocation))
bndl.putString("message", mapLocation);
return new MyMapFragment.newInstance(bndl);
}
}
public class MyMapFragment extends SupportMapFragment { //kanei extend thn hdh uparxousa class gia to maps ths google alla den mpoorume na thn doume giati einai kleidomenh
public String location="EMPTY";
public static MyMapFragment newInstance(Bundle bundle) {
MyMapFragment myMapFragment= new MyMapFragment ();
if (bundle != null) {
myMapFragment.setArguments(bundle);
}
return myMapFragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(getArguments()!=null)
location =getArguments().getString("message");
}
Here is the case that i would like to add a Google API into an action bar which goes to a fragment. But, it failed because the fragment class has to extends FragmentActivity while the action bar not allowed it, anyone could help to fix it? Thanks very much!
MainHome.java
package com.example.demo3;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainHome extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainhome);
initView();
}
private void initView() {
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
actionBar.addTab(actionBar
.newTab()
.setText("My Information")
.setTabListener(
new MyTabListener<FragmentPage1>(this,
FragmentPage1.class)));
actionBar.addTab(actionBar
.newTab()
.setText("My Location")
.setTabListener(
new MyTabListener<FragmentPage2>(this,
FragmentPage2.class)));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.prelog, menu);
return true;
}
}
Fragment2.java
package com.example.demo3;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class FragmentPage2 extends Fragment {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.locationhome, null, false);
map = ((SupportMapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
return v;
}
}
It brings that I need to extend FragmentActivity to enable
map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
. However, it will make
actionBar.addTab(actionBar
.newTab()
.setText("My Location")
.setTabListener(
new MyTabListener<FragmentPage2>(this,
FragmentPage2.class)));
failed. Anyone could have some suggestion?
Thanks very much!
use mapview instead of mapfragment like this
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and modify java file like this
public class MyMapFragment extends Fragment {
private MapView mMapView;
private GoogleMap mMap;
private Bundle mBundle;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View inflatedView = inflater.inflate(R.layout.map_fragment, container, false);
try {
MapsInitializer.initialize(getActivity());
} catch (GooglePlayServicesNotAvailableException e) {
// TODO handle this situation
}
mMapView = (MapView) inflatedView.findViewById(R.id.map);
mMapView.onCreate(mBundle);
setUpMapIfNeeded(inflatedView);
return inflatedView;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBundle = savedInstanceState;
}
private void setUpMapIfNeeded(View inflatedView) {
if (mMap == null) {
mMap = ((MapView) inflatedView.findViewById(R.id.map)).getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
#Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
#Override
public void onDestroy() {
mMapView.onDestroy();
super.onDestroy();
}
}