Why does the Xoom crash when sending a bitmap from one activity to another using intents?

StackOverflow https://stackoverflow.com/questions/14710465

  •  06-03-2022
  •  | 
  •  

Вопрос

In my app, I take a screen shot of the current screen (using view.getDrawingCache) and send it to another activity as a bitmap using intents.

I have tested it on Galaxy Note 1, HTC one v, and Motorolla Xoom mz 604 tablet (10.1"). On the first two devices the code works fine. But on the Xoom tablet the code doesn't work: the tablet starts waiting for long time, and then app crashes.

What could be the reason behind this?

Это было полезно?

Решение

A bitmap of a screenshot can get really big on a tablet, since the screen resolution is likely higher. The problem is probably a memory issue. To overcome this, you can write the bitmap to a temporary file and send the path to the file to the activity.

Alternatively, if the activity you're launching is in the same application, you can use a global variable to hold the bitmap.

Другие советы

I guest the problem its because of OutOfMemoryError: bitmap size exceeds VM budget

To get rid from this problem you can try to make one static variable then access in second activity rather than sending bitmap into intent.

OR

You can save the bitmap in internal memory and send path of that bitmap in second activity.

So get more in please post the logcat.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top