If you are using Images in your Android app, sometimes you may face this run-time issue in Android development. This happens only in some of the Android devices. This error does not show up in the Android emulator. So until you test on some devices you can't find this error. The reason for this error is that there are security limitations in the Android OS. If restricts the memory of RAM to 16 MB for a single app. So even if you have 2 GB ram on your Android device, a single app can consume only up-to 16MB. That is the normal procedure.
Once I had to used twelve 1800*1700 pixel images some other images. So lets do a simple calculation.
1800*1700*3 = 9180000 bits
9180000 / 8 = 1147500 bytes
1147500 / 1024 = 1120.60 kB nearly equals to 1MB.
So each image costs nearly 1 MB in the RAM.
I had 12 of these images. Total of 12 MB.
Also I had some more images and my total memory of the app exceeds 16MB limit. So in some devices I got OutOfMemoryError in Bitmap factory.
The simple solution I followed is, I reduced the resolution of the images. Because 1800*1700 is way too much for an Android app. After reducing the resolution the error is fixed.
Please refer this developer document for more details on this issue.
https://developer.android.com/training/displaying-bitmaps/manage-memory.html
experience and experiments... Android development, Software Development, Image Pricessign with OpenCV and QT
Showing posts with label Experience. Show all posts
Showing posts with label Experience. Show all posts
Sunday, December 29, 2013
Friday, November 29, 2013
GitHub for Windows Install Error
GitHub for Windows is a great tool for Windows users like me.;-) To Install GitHub for Windows you need dotNet version 4.0 or above.
Even having dotNet 4.0 you might face an issue while installing GitHub for Windows. I also had to face following common issue.
"Application cannot be started. Contact the application vendor."
To solve that issue go to run in Windows start menu and then go to following link.
C:\Users\[Your User Name]\AppData\Local\Apps
Then delete the 2.0 folder. It is ok that some files cannot be deleted from that folder.
Then try to re-install Github. Then you can proceed without an issue.
Even having dotNet 4.0 you might face an issue while installing GitHub for Windows. I also had to face following common issue.
"Application cannot be started. Contact the application vendor."
To solve that issue go to run in Windows start menu and then go to following link.
C:\Users\[Your User Name]\AppData\Local\Apps
Then delete the 2.0 folder. It is ok that some files cannot be deleted from that folder.
Then try to re-install Github. Then you can proceed without an issue.
Monday, October 28, 2013
How to read Research Papers efficiently
Reading a Research paper is a really painful thing for most of the people. Sometimes we have to read few research papers within few hours/days. But some people take a whole day to read a single research paper. So lets see if there is any method do read a research paper quickly.
Most research papers contains two columns. Because that column width is comfortable to the human eye. Majority of the people read paper by reading words one by one. That is the most time consuming thing. So try to read a chunk of three words at once. This will be difficult at your first run. So keep practice. Later you'll save a lot of time when reading research paper.
The second method is avoiding the movement of your eye. You can concentrate your eye on the center of a line. Any avoid the leftmost and rightmost words. Read only middle words. That won't affect the meaning of the sentence. You can get the meaning of that sentence without reading the leftmost and rightmost words and it will save some time.
So aggregating these two methods, I have posted a photo below. You can understand using it.
You will have to practice this methods to get the advantage of it. With this method you will not grab the 100% of the contents of the research paper. But this method will give you a clear idea of the research paper and its relatedness to your research quickly. Good luck with your readings.!
Friday, October 4, 2013
Using Facade Design Pattern
When I doing my internship I came across a project which used Facade Design Pattern. So now I'm going to explain my experience with Facade Design pattern. This post will explain how to use Facade design pattern in simple terms.
Facade design pattern is not a harder pattern. If you are familiar with abstraction and information hiding you can understand it easily. First lets discuss what the meaning of information hiding. Encapsulation is a basic principle of OOP. When we using encapsulation we hide internal properties of an object. Simply we make the attributes of the object private and allow users to get and set their values through getter and setter methods. So the attribute is hidden from you. You can't directly refer that attribute by calling object.attribute (ex: human,name). You have to use human.getName() method to get name of that human object and human.setName("his name") method to set the name of that human object. That is the basic idea of information hiding. Abstraction is also bit similar to information hiding. We use abstraction to hide implementation details. As an example if we call the method car.drive(), that car will drive. But the user does not how the driving process happened. He only know that he called the drive method of that car object, and now the car is driving.
Facade design pattern is the next step to information hiding and abstraction. If you need a combination of few objects to get some work done, you can use Facade pattern to hide that combination information from the user. Think the user gives a command like build a car object. ClientHandler class is the one which handles user request. Building a car is a very complex thing. You need combination of several objects to get that car built. There are several departments in a car factory. Like Building engine and stuff, Building chassis of the car, building tires, assembling department and painting department. So at the ClientHandler class, if you call all these department objects and do the car building, that will be a mess. And that will expose the internal implementation details to the user.
So we introduce a facade class just after the ClientHandler class. In that facade class we can write a method called buildCar() and that will arrange all the department objects and build the car. So the ClientHandler only needs to call buildCar() method of the Facade class. So all the combination and implementation details are hidden from the ClientHandler class.
Hope you got an idea on the Facade Design Pattern and how to use the Facade Design Pattern. What I want with this blog to help my readers to describe complex thing in simple term. There are lots of articles on these topics. But there are not much easier to learn to a beginner. So I want to share my experience with this blog.
Facade design pattern is not a harder pattern. If you are familiar with abstraction and information hiding you can understand it easily. First lets discuss what the meaning of information hiding. Encapsulation is a basic principle of OOP. When we using encapsulation we hide internal properties of an object. Simply we make the attributes of the object private and allow users to get and set their values through getter and setter methods. So the attribute is hidden from you. You can't directly refer that attribute by calling object.attribute (ex: human,name). You have to use human.getName() method to get name of that human object and human.setName("his name") method to set the name of that human object. That is the basic idea of information hiding. Abstraction is also bit similar to information hiding. We use abstraction to hide implementation details. As an example if we call the method car.drive(), that car will drive. But the user does not how the driving process happened. He only know that he called the drive method of that car object, and now the car is driving.
Facade design pattern is the next step to information hiding and abstraction. If you need a combination of few objects to get some work done, you can use Facade pattern to hide that combination information from the user. Think the user gives a command like build a car object. ClientHandler class is the one which handles user request. Building a car is a very complex thing. You need combination of several objects to get that car built. There are several departments in a car factory. Like Building engine and stuff, Building chassis of the car, building tires, assembling department and painting department. So at the ClientHandler class, if you call all these department objects and do the car building, that will be a mess. And that will expose the internal implementation details to the user.
So we introduce a facade class just after the ClientHandler class. In that facade class we can write a method called buildCar() and that will arrange all the department objects and build the car. So the ClientHandler only needs to call buildCar() method of the Facade class. So all the combination and implementation details are hidden from the ClientHandler class.
Hope you got an idea on the Facade Design Pattern and how to use the Facade Design Pattern. What I want with this blog to help my readers to describe complex thing in simple term. There are lots of articles on these topics. But there are not much easier to learn to a beginner. So I want to share my experience with this blog.
Friday, September 20, 2013
Abstract Factory Design Pattern
Few days ago I had to help my friend to do his college assignment. He is new to programming field but he was asked to develop a java program to implement a system which includes Abstract Factory Design Pattern.
I didn't have any experience with abstract factory design pattern. The only thing I know was that it is a Creational Design pattern. So I did some research on that design pattern. But I felt abstract factory design is bit difficult to understand. So I decided to write a blog post on my experience. So this will be an comparison between Factory pattern and the Abstract Factory pattern.
The first thing which I had to consider is the difference between the Factory Design pattern and the Abstract Factory design pattern. Both are bit similar. But Abstract Factory design pattern is one step ahead than the factory design pattern.
The Factory design pattern only hides the instantiation logic from the client. When the user ask for a new object the factory class calls createObject() method and returns a instance of that object. That instance is what only see by the user. He does not know the instantiation logic. Below diagram will show the logic.
source: http://www.oodesign.com
Abstract Factory design pattern is one step above than the Factory pattern. In the Factory design pattern you only gave an interface to handle one object. But this pattern gives an interface to creating few related objects. Simply it hides the factory. Below diagram will show the logic.
source: http://www.oodesign.com
But that diagram does not describe the whole thing. So here after I will describe my implementation.
In that assignment, he was asked to implement a system for banking environment including accounts, loans and staff. Most importantly, he has to use Abstract Factory design pattern.
First I built three abstract classes for Account, Loan and Staff. By extending them I built Savings, Current and Kids Accounts, Personal and Housing loans and Temporary and Permanent Staff classes.
Then I implemented Three Factory classes which included Factory design pattern. Those factory classes are Account handler, Loan Handler and Staff Handler. Those will do the job of Factory design pattern. Single handler class will do the abstraction of one type of object.(ex: AccountHandler will hides the implementation of Account objects.)
Then my task was to implement the Abstract Factory pattern. So I considered a scenario of two banks called Bank A and Bank B. Generally both banks have the save structure. So I used an abstract class called AbstractBankFactory. By extending that class you can build any bank. Those bank classes will handle the abstraction of their internal operations.
Now the client can easily call bank.createAccount() method to create an Account.
Below code is the AbstractBankFactory
And this is how the user should use it.
User only needs to call bank.createAccount() method to create. Also if he needs to take a loan, he will need to call bank.takeLoan(). If he needs to deposit money, he will need to call bank.deposit(accountNo). This method is just like the real banking environment. When the client go to the bank, he does not need to how the internal operations are executed. He only needs to get done what he wanted. When he call bank.createAccount() bank will return a bank account for that user. When he wants to get a loan, he can call bank.getLoan(variables) and pass necessary variables, bank will return a loan for that customer. This is just like the factory pattern. But in the factory pattern you only hides one object type. But in this implementation you can hide the implementation of both Account and Loan objects. Simply it hides the factory called bank.
In this blog post I wanted to share my experience on Abstract Factory design pattern. Because in most articles which I came across didn't have proper description. Those had only the basic idea. Also this blog post differentiate the Factory Design Pattern and the Abstract Design Pattern.
If you have any concern please feel free to post a comment below. Also if you need the complete code, please mention it in the comment. Thank you.
Subscribe to:
Posts (Atom)