简体   繁体   中英

Prevent Android app from crashing while reading a file that is too large

In the Xamarin Android app I'm making, I have a service that processes files. But when it's reading a file that is taking too much memory, it crashes the app, without any exception.

Is there a way to gracefully let the user know that this files is too large.

What I could do is determine the size of the file beforehand, but it depends on the device's memory how much it can handle, right?

Any help or suggestion is welcome :)

Since I can't see your code, so here just some advice, you could run your Xamarin.Android project with a larger heap size.

You could refer to this question . As JonathanPryor said, you can provide the $(JavaMaximunHeapSize) and $(JavaOptions) MSBuild properties to let Java allocate enough memory to complete your build.

Method 1 :

You can do this by hand-editing your .csproj and adding the following section:

<PropertyGroup>
    <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
</PropertyGroup>

Method 2 :

Click your project Properties -> Android Options -> Advanced -> Java Max Heap Size , set the value with "1G".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM