Question

I am using google map in my application and display markers.

Now on click of marker window I want to replace the current fragment with other fragment.

for (StoreData store : comp.getArrStoreList()) {
                LatLng l = new LatLng(Double.parseDouble(store.getLat()),
                        Double.parseDouble(store.getLng()));

                MarkerOptions marker = new MarkerOptions()
                        .position(l)
                        .title(store.getName())
                        .snippet(store.getCity())
                        .icon(BitmapDescriptorFactory
                                .defaultMarker(BitmapDescriptorFactory.HUE_AZURE));

                Marker mrkr = mapCompanyList.addMarker(marker);

                CompanyStoreData companyStoreData = new CompanyStoreData();

                companyStoreData.setStoreData(store);

                companyStoreData.setCompanyId(comp.getId());

                listStoreData.put(mrkr, companyStoreData);


                mapCompanyList
                .setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                    @Override
                    public void onInfoWindowClick(Marker marker) {

                        try {

                            StoreDetailsFragment storeDetails = new StoreDetailsFragment();
                            Bundle b = new Bundle();

                            b.putSerializable(UserDefaults.STORE_OBJECT,
                                    listStoreData.get(marker).getStoreData());
                            b.putString("StoreAppID", listStoreData.get(marker).getCompanyId());

                            storeDetails.setArguments(b);

                            ((BaseTabbarContainer) companyListFragment.getParentFragment()).replaceFragment(
                                    storeDetails, true); // here my UI is hang

                        } catch (Exception e) {
                            Log.e("Exception", "Exception :: " + e.getMessage());
                        }

                    }
                });
            }

I am creating one hashmap which has <marker,storedata> marker as a key and storedata (my custom class object) as a value.

on onInfoWindowClick I am getting instance of store data on basis of key of hashmap(). It is working well but

((BaseTabbarContainer) companyListFragment.getParentFragment()).replaceFragment(
                                        storeDetails, true);  

Here my UI is getting hang. What is the issue

Was it helpful?

Solution

I resolved the issue . if any one facing this issue please refer this.

What I done is create one handler to run the code snippet after some delay and return from the onInfoWindowClick method after calling handler.

mapCompanyList
                .setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                    @Override
                    public void onInfoWindowClick(Marker marker) {

                        final Marker mark = marker;
                        try {

                            new Handler().postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    callStore(mark);
                                }
                            }, 100);


                            return;
                        } catch (Exception e) {
                            Log.e("Exception", "Exception :: " + e.getMessage());
                        }

                    }
                });

callStore

    private void callStore(Marker marker) {
        StoreDetailsFragment storeDetails = new StoreDetailsFragment();
        Bundle b = new Bundle();

        b.putSerializable(UserDefaults.STORE_OBJECT,
                listStoreData.get(marker).getStoreData());
        b.putString("StoreAppID", listStoreData.get(marker).getCompanyId());

        storeDetails.setArguments(b);

        ((BaseTabbarContainer) CompanyListFragment.this.getParentFragment()).replaceFragment(
                storeDetails, true);

    }

and It worked;

But I still don't get why it is getting hang though and why it is resolved after returning from onInfoWindowClick method while running code in post delay?if any one have any idea please share.

OTHER TIPS

I was also facing this problem, for me I solved by stop using fragmentManager.executePendingTransactions(), if I use this line to replace fragment then its just HANG, but without this line its working without any problem. hope it will help for someone who will face similar problem. thanks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top