Reputation: 71
I have the following code:
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.v(StartupActivity.TAG, "SURFACE CREATED");
bitmaps = new HashMap<>();
bitmaps.put("logo", BitmapFactory.decodeResource(getContext().getResources(), R.drawable.logo));
displayLoadingBitmap();
bitmaps.remove("logo");
System.gc();
....
}
The surface is created immediately but my bitmap appears a little bit late. Is there a way to preload bitmap in for example StartupActivity and send it to the current Activity just to display it?
Upvotes: 0
Views: 735
Reputation: 29285
Yes, you can preload that bitmap in the start activity and pass it to the target activity.
In order to send that bitmap, since bitmaps implement Parceable
, they can be serialized and passed to another activity.
StartUpActivity:
Intent intent = new Intent(this, TargetActivity.class);
intent.putExtra("image", bitmap);
TargetActivity:
Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("image");
Alternatively you're recommended to use Picasso library which handles all stuff you would need about caching and fetching images.
Upvotes: 2