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

Error: Trying to requery an already closed cursor
PreferenceScreen launch activity
Android startActivity with intent doesn't work
ListView contentview change from external xml file
Resources$NotFoundException: Resource is not a Drawable
Sending multiple emails through Gmail smtp using javax mail class triggers connection refused error occasionally
The icon app android is small
How to distribute updates to users of pre-installed paid Android App?
Eclipse The R class is not being built for my android projects
Progress bar with 2 Indicators
how i get the contact list in multiselect or checklist view?
handling collision in game android
Handling click events for listview in ViewPager android
Android WebView Fails to Completely Render Content Until User Interaction
Tint effect in Android
any sbstitute way to fetch file path of stored pictures

Categories

HOME
batch-file
facebook-oauth
hyperlink
hessian
square
jquery-ui-sortable
little-proxy
spring-social
automatic-ref-counting
symmetricds
screen-readers
gruntfile
esoteric-languages
google-content-api
corenlp-server
event-flow
kodi
android-sugarorm
yowsup
swagger-php
git-rewrite-history
mongoose-schema
jvmti
vmware-fusion
android-ibeacon
fwrite
vugen
posixct
trojan
aquamacs
pair-programming
boxing
yii2-user
colorbar
opengl-4
cup
gameplay-kit
restore
rmongo
qtplugin
envi
uicolor
angular-ui-typeahead
kiosk
redis-cluster
libvlc
microsoft-reporting
dulwich
snoop
zxspectrum
cakephp-2.7
apache-spark-1.3
boost-program-options
jbake
big-ip
human-computer-interface
angular-carousel
gnumeric
twitter-bootstrap-rails
gtm-oauth2
sphinxql
http-patch
traceability
preload
curb
tree-balancing
koken
isa-swizzling
infobright
webdev.webserver
rmdir
collectionviewsource
zend-rest
openfaces
zen

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