android


Android OutOfMemoryError when Fragment's onCreateView called


I have an Activity with fragment inside. On some devices like Xiaomi application crashes and OutOfMemoryError thrown. There's stacktrace:
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 9437196 byte allocation with 5089232 free bytes and 4MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:613)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:446)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.createFromResourceStream(Resources.java:2937)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2669)
at android.content.res.Resources.loadDrawable(Resources.java:2569)
at android.content.res.TypedArray.getDrawable(TypedArray.java:872)
at android.widget.ImageView.<init>(ImageView.java:152)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:963)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1022)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at com.rcd.perfecto.ui.fragments.AuthFragment.onCreateView(AuthFragment.java:154)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1988)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1250)
at android.support.v4.app.FragmentManagerImpl.dispatchReallyStop(FragmentManager.java:2148)
at android.support.v4.app.FragmentController.dispatchReallyStop(FragmentController.java:247)
at android.support.v4.app.FragmentActivity.onReallyStop(FragmentActivity.java:804)
at android.support.v4.app.FragmentActivity.doReallyStop(FragmentActivity.java:790)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:367)
at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:181)
at android.app.Activity.performDestroy(Activity.java:6474)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1143)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3823)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3854)
at android.app.ActivityThread.access$1500(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1403)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5432)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:735)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
The exception is thrown when called onCreateView method of AuthFragment. There's method:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_auth, container, false);
ButterKnife.bind(this, view);
return view;
}
Exception is thrown on line View view = inflater.inflate(R.layout.fragment_auth, container, false); What can I do to solve this problem?
You can use largeHeap in your Application. Just add to Manifest:
<application
...
android:largeHeap="true"
...

Related Links

Failed to install the Android studio application on my phone [duplicate]
LibGDX Resolution too big
Get child ID from Firebase android [closed]
When is it safe to programatically access fragment view
How to track facebook current user's location IOS/Android
Making a keyboard app on one android phone to act as a Bluetooth keyboard for another android phone
download expansion files manually
Android form-“error-snackbar” implementation
How to display TextView Right to left ever if starts with Left to right char (English , numbers and more..)?
attachment not added to email intent
is there a broadcast receiver that broadcasts when a new device is connected/disconnected to my hotspot? [duplicate]
How to add Smooth Scroll in MuPDF?
How to set default ringtone from ringtones programmatically
Android transformClassesWithJarMergingForDebug
onClick is not working in cardView
Delphi 10.1 Android How to get Firebase Device Token

Categories

HOME
beautifulsoup
twitter-bootstrap-3
deep-learning
eslint
android-studio-2.2
pda
jmx
spring-data-redis
google-cloud-functions
boto3
barcode
joomla3.0
p2p
redis-sentinel
angular-dart
openbugs
do-while
altera
dynamic-sql
job-scheduling
intershop
digital-signature
strongname
game-theory
fable-f#
delimiter
spotipy
winexe
cppreference
carrierwave
realm-mobile-platform
python-2.6
playstation-portable
erb
sharding
slacktextviewcontroller
python-pptx
apic
urlsession
setup.py
laravel-elixir
parser-generator
ssrs-2014
placeholder
file-sharing
procfile
jide
flask-restful
jquery-ui-draggable
spring-integration-sftp
qtranslate
dt
gpg-signature
cpu-cache
cvxpy
cudd
pacemaker
jtwig
cassia
boost-serialization
database-relations
halcon
dynamics-nav-2016
toran-proxy
rewrite
phonertc
eoferror
apache-commons-daemon
canvg
ghcjs
sonarqube-5.0
spy++
ignite-ui
lambda-architecture
live555
qscrollarea
multitasking
ecslidingviewcontroller
cmmi
android-icons
traceability
dopostback
uimanageddocument
os.system
infobright
agility.js
user-tracking
xcelsius
strsep
drupal-fivestar
alsb

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App