多次与应用共享图像后,内存不足异常

时间:2018-09-14 15:41:09

标签: java android android-studio share

我有一个共享图像的应用程序。通常它可以正常工作,但是在5或6次共享后,当我尝试与它共享另一个图像时,应用程序崩溃了,错误消息是OutOfMemory Exception。崩溃后,共享可以正常工作约5-6股,然后再次崩溃。 我的问题是如何纠正此问题。 这是错误:

09-14 18:28:59.290 2224-2224/com.example.user.aitzik4 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.OutOfMemoryError
    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623)
    at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:378)
    at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:417)
    at android.graphics.drawable.Drawable.createFromPath(Drawable.java:934)
    at android.widget.ImageView.resolveUri(ImageView.java:660)
    at android.widget.ImageView.setImageURI(ImageView.java:393)
    at com.example.user.aitzik4.MainActivity.onCreate(MainActivity.java:114)
    at android.app.Activity.performCreate(Activity.java:5283)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
    at android.app.ActivityThread.access$700(ActivityThread.java:150)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5279)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)

这是我的MainActivity:

https://pastebin.com/x0bDdDLe

获取图像的功能称为handleSendImage()

谢谢!

1 个答案:

答案 0 :(得分:0)

AndroidManifest.xml

  

android:largeHeap =“ true”

 <application
    android:name="com.xxx.xx"
    android:allowBackup="true"
    android:icon="@mipmap/icon"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/icon"
    android:supportsRtl="true"
    android:largeHeap="true"
    android:theme="@style/AppTheme">

        -----

  </application>