Reputation: 427
This question only pertains to the development of Android applications.
When the orientation of the screen is changed, the Activity restarts, but not the Application. As a result, Bitmaps often must be re-instantiated.
But by putting the Bitmaps in a class that extends Application, those Bitmaps won't be re-instantiated.
public class MainApplication extends Application {
Bitmap bmp;
@Override
public void onCreate(){
super.onCreate();
bmp=BitmapFactory.decodeResources(getResources(),R.drawable.bmp);
}
}
Wouldn't that make the Application more efficient? However, I have not seen anyone do anything like this, so I deduct that there is probably a downside to this.
So, getting to the question, why shouldn't I do this?
Upvotes: 0
Views: 59
Reputation: 2737
In Android you usually have a very limited memory(because of old devices) so keeping Bitmaps(might have a huge size) in memory is a very risky decision. Also, it's better to resize bitmaps so they take only the necessary memory, and the scale may change if the orientation does.
Upvotes: 3