I'm developing an application with a menu which contains a list of buttons, when you click one of these buttons, another activity (the same activity with different image for each button) is opened showing an imageview. The problem is that when i click several times in different buttons (opening new images) the app crashes and i'm not able to solve it. Any help? Thanks.
Asked
Active
Viewed 169 times
0
-
Is necessary you said what platform is (I think so is in android, because Out Of Memory is common in android), other thing is sometimes is necessary add the exception for know what king of Out Of Memory is. I will answer your question for an images android problems. – Maria Mercedes Wyss Alvarez Jul 26 '13 at 18:00
-
Yes, the platform is Android, and the exception I'm sure that is "bitmap size exceeds vm budget", how can Eclipse show error when i run the application in a device, not emulator? The problem is with a HTC Desire device, with a Nexus 4 the app works great. – Dv Apps Jul 26 '13 at 18:07
-
I post and answer for resolve the most common OutOfMemory error, but no is your specific case, you can whatch these other post here in stackoverflow this (1) http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/823966#823966 or thise (2) http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object Basically the problem is the form when you create the bitmap. – Maria Mercedes Wyss Alvarez Jul 26 '13 at 18:12
-
The problem is that i don't use bitmaps, i'm using a library called PhotoView and i have to use drawable instead – Dv Apps Jul 26 '13 at 18:14
1 Answers
1
That problem is because your are using a lot of images in your views and never clean the memory, then in one momento your don't have more memory for the new ones.
One form to resolve that problem is cleaning the memory always your destroy and activity. You can override the next method in your activity for clean the memory.
@Override
public void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
that method review a view, in your case those views will be your ImageView and ImageButton. Finally you need call this method in the method onDestroy() (need override that method too).

Maria Mercedes Wyss Alvarez
- 527
- 4
- 16
-
-
Hello again, can you explain me how implement the method onDestroy() int his case and when it is called? – Dv Apps Jul 28 '13 at 09:33
-
I'm using a PhotoviewAttacher object of this project: https://github.com/chrisbanes/PhotoView/tree/master/sample and when i click a button i create a new Photoview attacher object. Your code doesn't work me, i cannot override the unbindDrawables method and i don't know why but something breaks the application. – Dv Apps Jul 28 '13 at 09:44
-
Ok, your problem is, your really don't know much about android development, first I suggest reading few about Activity lifecycle http://developer.android.com/training/basics/activity-lifecycle/index.html onDestroy() is a method to the Activity lifecyle you need override it in your ACTIVITY, second I I think it was very clear in saying that it should override the method in your ACTIVITY, third when you create a PhotoViewAttacher object, you send and ImageView object, that ImageView is the View that the unbindDrawables method waiting. (continue in the next comment) – Maria Mercedes Wyss Alvarez Jul 29 '13 at 05:49
-
finally call this method always you make click on the button, destroy the last ImageView you create and put in your PhotoViewAttacher and then create the new PhotoViewattacher with the new ImageView. Finally if that don't work for your, you need post a new question here specifying your real problem, because in your question your only talked about and images problem, you need say clearly is a problem with the PhotoView Library, and is better is you put the exception. You should also consider using another library, if your finally is make zoom I have other more simple code for do that. – Maria Mercedes Wyss Alvarez Jul 29 '13 at 05:50