Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Liutauras Vilda
Henry Wong
Devaka Cooray
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Al Hobbs
Carey Brown
Bartenders:
Piet Souris
Mikalai Zaikin
Himai Minh
Forum:
Android
FragmentActivity causing activity leaks (IntentReceiver) but not on MapActivity
aries dimagiba
Greenhorn
Posts: 20
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi guys,
Basically, I've already asked this question here:
http://stackoverflow.com/questions/23402087/fragmentactivity-causing-activity-leaks-intentreceiver-but-not-on-mapactivity
Hoping to get some answer here. Many thanks
ibrahim yener
Ranch Hand
Posts: 202
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Without code means almost no reply.
Could you please explain that how do you expect someone help you without actually see your code.
Probably, you won't get any help not even here or in stackoverflow.
My Google play account
aries dimagiba
Greenhorn
Posts: 20
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi ibrahim yener,
Many thanks for the quick reply. Sorry about that, well here's the codes.
Some are omitted to show only the codes where i am experiencing issues
** Using MapActivity ** public class MyMapActivity extends MapActivity { public MapView mapView; protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.my_map_activity); mapView = (MapView) findViewById(R.id.my_map); showAllAvailableOverlays(); } private void showAllAvailableOverlays() { Bitmap trafficBitmap = null; List<TrafficProfileDummyModel> dummyTrafficProfiles = new TrafficProfileMockDataSource().getTrafficProfiles(); for(TrafficProfileDummyModel dtp : dummyTrafficProfiles) { View trafficProfileView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.traffic_profile_custom_overlay_item, null); ImageView trafficProfileImageView = (ImageView) trafficProfileView.findViewById(R.id.traffic_profile_image_overlay); TextView trafficProfileCurrentText = (TextView) trafficProfileView.findViewById(R.id.traffic_profile_custom_overlay_item_currentspeed); TextView trafficProfileAverageText = (TextView) trafficProfileView.findViewById(R.id.traffic_profile_custom_overlay_item_averagespeed); int curr = (int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()), ave = Integer.parseInt(dtp.getTrafficProfileHistorical()); trafficProfileCurrentText.setText(String.format("%02d",curr)); trafficProfileAverageText.setText(String.format("%02d",ave)); Drawable trafficProfileMarkerOverlay = null; trafficBitmap=null; final GeoPoint geopoint = dtp.getGeopoint(); if((int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) >= 0 && (int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) < 35 ) { // set marker color to red trafficProfileImageView.setImageDrawable(getResources().getDrawable(R.drawable.traffic_profile_red)); //trafficProfileImageView.setBackground(getResources().getDrawable(R.drawable.traffic_profile_red)); trafficBitmap = bitmapScalerAndResizer.createDrawableFromView(MyMapActivity.this, trafficProfileView); trafficProfileMarkerOverlay = new BitmapDrawable(getResources(),trafficBitmap); } else if ((int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) >= 35 && (int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) < 49) { // set marker color to yellow trafficProfileImageView.setImageDrawable(getResources().getDrawable(R.drawable.traffic_profile_yel)); trafficBitmap = bitmapScalerAndResizer.createDrawableFromView(MyMapActivity.this, trafficProfileView); trafficProfileMarkerOverlay = new BitmapDrawable(getResources(),trafficBitmap); } else if ((int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) >= 50) { // set marker color to green trafficProfileImageView.setImageDrawable(getResources().getDrawable(R.drawable.traffic_profile_green)); trafficBitmap = bitmapScalerAndResizer.createDrawableFromView(MyMapActivity.this, trafficProfileView); trafficProfileMarkerOverlay = new BitmapDrawable(getResources(),trafficBitmap); } final DefaultItemizedOverlay overlay = new DefaultItemizedOverlay(trafficProfileMarkerOverlay); final OverlayItem overlayItem = new OverlayItem(geopoint, "", ""); overlay.addItem(overlayItem); overlay.setTapListener(new ItemizedOverlay.OverlayTapListener() { @Override public void onTap(GeoPoint pt, MapView mapView) { [b]// this pauses the current activity but doesn't produce intent receiver leaks on activity finish() Intent trafficProfileIntent = new Intent(MyMapActivity.this, TrafficProfilePopUpActivity.class); startActivity(trafficProfileIntent); [/b] } }); mapView.getOverlays().add(overlay); } trafficBitmap.recycle(); mapView.invalidate(); } } ** TrafficProfilePopUpActivity (the popup window with viewpager & fragments)** public class TrafficProfilePopUpActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.gravity = Gravity.NO_GRAVITY; params.x = 0; params.y = -200; getWindow().setAttributes(params); setContentView(R.layout.traffic_profile_viewpager_prompt_layout); TrafficProfilePagerAdapter pageAdapter = new TrafficProfilePagerAdapter(getSupportFragmentManager(), getFragments()); ViewPager pager = (ViewPager)findViewById(R.id.myViewPager); pager.setAdapter(pageAdapter); CirclePageIndicator circlePageIndicator = (CirclePageIndicator) findViewById(R.id.viewPagerIndicator); circlePageIndicator.setViewPager(pager,0); } private List<Fragment> getFragments(){ List<Fragment> fList = new ArrayList<Fragment>(); fList.add(new TrafficProfile_9am_Fragment()); fList.add(new TrafficProfile_12pm_Fragment()); fList.add(new TrafficProfile_3pm_Fragment()); fList.add(new TrafficProfile_6pm_Fragment()); fList.add(new TrafficProfile_9pm_Fragment()); return fList; } } ================================================================= ** Using FragmentActivity ** public class MyMapActivity extends FragmentActivity { public MapView mapView; protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.my_map_activity); mapView = (MapView) findViewById(R.id.my_map); showAllAvailableOverlays(); } private void showAllAvailableOverlays() { Bitmap trafficBitmap = null; List<TrafficProfileDummyModel> dummyTrafficProfiles = new TrafficProfileMockDataSource().getTrafficProfiles(); for(TrafficProfileDummyModel dtp : dummyTrafficProfiles) { View trafficProfileView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.traffic_profile_custom_overlay_item, null); ImageView trafficProfileImageView = (ImageView) trafficProfileView.findViewById(R.id.traffic_profile_image_overlay); TextView trafficProfileCurrentText = (TextView) trafficProfileView.findViewById(R.id.traffic_profile_custom_overlay_item_currentspeed); TextView trafficProfileAverageText = (TextView) trafficProfileView.findViewById(R.id.traffic_profile_custom_overlay_item_averagespeed); int curr = (int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()), ave = Integer.parseInt(dtp.getTrafficProfileHistorical()); trafficProfileCurrentText.setText(String.format("%02d",curr)); trafficProfileAverageText.setText(String.format("%02d",ave)); Drawable trafficProfileMarkerOverlay = null; trafficBitmap=null; final GeoPoint geopoint = dtp.getGeopoint(); if((int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) >= 0 && (int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) < 35 ) { // set marker color to red trafficProfileImageView.setImageDrawable(getResources().getDrawable(R.drawable.traffic_profile_red)); //trafficProfileImageView.setBackground(getResources().getDrawable(R.drawable.traffic_profile_red)); trafficBitmap = bitmapScalerAndResizer.createDrawableFromView(MyMapActivity.this, trafficProfileView); trafficProfileMarkerOverlay = new BitmapDrawable(getResources(),trafficBitmap); } else if ((int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) >= 35 && (int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) < 49) { // set marker color to yellow trafficProfileImageView.setImageDrawable(getResources().getDrawable(R.drawable.traffic_profile_yel)); trafficBitmap = bitmapScalerAndResizer.createDrawableFromView(MyMapActivity.this, trafficProfileView); trafficProfileMarkerOverlay = new BitmapDrawable(getResources(),trafficBitmap); } else if ((int)Math.round(MyMapActivity.this.currentTripDataModel.getCurrentAverageSpeed()) >= 50) { // set marker color to green trafficProfileImageView.setImageDrawable(getResources().getDrawable(R.drawable.traffic_profile_green)); trafficBitmap = bitmapScalerAndResizer.createDrawableFromView(MyMapActivity.this, trafficProfileView); trafficProfileMarkerOverlay = new BitmapDrawable(getResources(),trafficBitmap); } final DefaultItemizedOverlay overlay = new DefaultItemizedOverlay(trafficProfileMarkerOverlay); final OverlayItem overlayItem = new OverlayItem(geopoint, "", ""); overlay.addItem(overlayItem); overlay.setTapListener(new ItemizedOverlay.OverlayTapListener() { @Override public void onTap(GeoPoint pt, MapView mapView) { [b]// this does not pauses the current activity but when activity closes/finish, produces the intentreceiver leaks final TrafficProfileDialogFragment trafficProfileDialog = new TrafficProfileDialogFragment(); trafficProfileDialog.show(getSupportFragmentManager(),"");[/b] } }); mapView.getOverlays().add(overlay); } trafficBitmap.recycle(); mapView.invalidate(); } } ** TrafficProfileDialogFragment (the popup-like dialog with viewpager & fragments inside) ** public class TrafficProfileDialogFragment extends android.support.v4.app.DialogFragment { @SuppressWarnings("deprecation") @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final View trafficProfileDialogFragment = this.onCreateView(getActivity().getLayoutInflater(), null, savedInstanceState); final Dialog dialog = new Dialog(getActivity(), R.style.DialogCustomTheme); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); lp.dimAmount=0.90f; // Dim level. 0.0 - no dim, 1.0 - completely opaque lp.y = 75; lp.height = 300; lp.width = 300; dialog.getWindow().setAttributes(lp); dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL|Gravity.TOP); dialog.getWindow().setBackgroundDrawable(new BitmapDrawable()); dialog.setContentView(trafficProfileDialogFragment); dialog.setCanceledOnTouchOutside(true); return dialog; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View trafficProfileDialogFragment = inflater.inflate(R.layout.traffic_profile_viewpager_prompt_layout, container, false); TrafficProfilePagerAdapter pageAdapter = new TrafficProfilePagerAdapter(getChildFragmentManager(), getFragments()); ViewPager pager = (ViewPager) trafficProfileDialogFragment.findViewById(R.id.myViewPager); pager.setAdapter(pageAdapter); CirclePageIndicator circlePageIndicator = (CirclePageIndicator) trafficProfileDialogFragment.findViewById(R.id.viewPagerIndicator); circlePageIndicator.setViewPager(pager,0); return trafficProfileDialogFragment; } private List<Fragment> getFragments(){ List<Fragment> fList = new ArrayList<Fragment>(); fList.add(new TrafficProfile_9am_Fragment()); fList.add(new TrafficProfile_12pm_Fragment()); fList.add(new TrafficProfile_3pm_Fragment()); fList.add(new TrafficProfile_6pm_Fragment()); fList.add(new TrafficProfile_9pm_Fragment()); return fList; } }
Hope you can help me with this issue. Thanks
aries dimagiba
Greenhorn
Posts: 20
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I've managed to somehow solved the issue by calling mapView.destroy() on the Activity's onDestroy() method. Many thanks guys.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
OutOfMemoryError : Suggestions for debugging
can the cause of memory leak be detected here?
PopUpWindow with Fragments inside implemented on MapActivity without using FragmentActivity
Questions on Pro Android 3
android.app.IntentReceiverLeaked: Activity
More...