android - Switching to Activity1 (RecyclerView) to Activity2 (RecyclerView) -
please me problem. have 2 activity recyclerview each of them. problem, when open activity1 , pressed open activity2, loads when scrolling application unfortunately closing.
each activity has adapter , holder. did forgot finish activity onbackpressed? code should put , put? thank you!
activity.java
package com.bne; import android.app.activity; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.defaultitemanimator; import android.support.v7.widget.linearlayoutmanager; import android.support.v7.widget.recyclerview; import android.support.v7.widget.toolbar; public class festivals extends appcompatactivity { string[] names; string[] location; int[] images ={}; string[] date; string[] about; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.festivals); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); getsupportactionbar().setdisplayhomeasupenabled(true); getsupportactionbar().setdisplayshowhomeenabled(true); recyclerview recyclerview = (recyclerview) findviewbyid(r.id.festivals); names = getresources().getstringarray(r.array.festival_name); location = getresources().getstringarray(r.array.festival_location); date = getresources().getstringarray(r.array.festival_date); = getresources().getstringarray(r.array.festival_about); recyclerview.setlayoutmanager(new linearlayoutmanager(this)); recyclerview.setitemanimator(new defaultitemanimator()); festivalsadapter adapter = new festivalsadapter(this, names, location, images, date, about); recyclerview.additemdecoration(new divideritemdecoration(this, linearlayoutmanager.vertical)); recyclerview.setadapter(adapter); } @override public boolean onsupportnavigateup() { onbackpressed(); return true; } }
adapter.java
package com.bne; import android.content.context; import android.content.intent; import android.graphics.typeface; import android.support.v7.widget.recyclerview; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; public class festivalsadapter extends recyclerview.adapter <festivalsholder> { context festivals; string [] name, location, date, about; int [] images; public festivalsadapter(context festivals, string [] name, string [] location, int [] images, string [] date, string [] about) { this.festivals = festivals; this.name = name; this.location = location; this.images = images; this.date = date; this.about = about; } @override public festivalsholder oncreateviewholder(viewgroup parent, int viewtype) { view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.festivals_recycler, null); festivalsholder festivalsholder = new festivalsholder(view); typeface content = typeface.createfromasset(festivals.getassets(), "fonts/cantarell.ttf"); typeface header = typeface.createfromasset(festivals.getassets(), "fonts/avenir.ttf"); festivalsholder.name.settypeface(header, typeface.bold); festivalsholder.location.settypeface(content); festivalsholder.date.settypeface(content); festivalsholder.about.settypeface(content); return festivalsholder; } @override public void onbindviewholder(festivalsholder holder, int position) { holder.name.settext(name[position]); holder.location.settext(location[position]); holder.images.setimageresource(images[position]); holder.date.settext(date[position]); holder.about.settext(about[position]); holder.setplacesitemclicklistener(new itemclicklistener() { @override public void onitemclick(view view, int position) { intent intent = new intent(festivals, festivaldetails.class); intent.putextra("name", name[position]); intent.putextra("location", location[position]); intent.putextra("images", images[position]); intent.putextra("date", date[position]); intent.putextra("about", about[position]); festivals.startactivity(intent); } }); } @override public int getitemcount() { return name.length; } }
holder.java
package com.bne; import android.support.v7.widget.recyclerview; import android.view.view; import android.widget.imageview; import android.widget.textview; public class festivalsholder extends recyclerview.viewholder implements view.onclicklistener { imageview images; textview name, location, date, about; private itemclicklistener itemclicklistener; public festivalsholder(view itemview) { super(itemview); images = (imageview) itemview.findviewbyid(r.id.festivals_image); name = (textview) itemview.findviewbyid(r.id.festivals_name); location = (textview) itemview.findviewbyid(r.id.festivals_location); date = (textview) itemview.findviewbyid(r.id.festivals_date); = (textview) itemview.findviewbyid(r.id.festivals_about); itemview.setonclicklistener(this); } @override public void onclick(view view) { this.itemclicklistener.onitemclick(view, getlayoutposition()); } public void setplacesitemclicklistener (itemclicklistener itemclicklistener) { this.itemclicklistener = itemclicklistener; } }
logcat:
07-28 21:31:16.602 30354-30354/com.bne e/androidruntime: fatal exception: main process: com.bne, pid: 30354 java.lang.outofmemoryerror: failed allocate 7200012 byte allocation 2024544 free bytes , 1977kb until oom @ dalvik.system.vmruntime.newnonmovablearray(native method) @ android.graphics.bitmapfactory.nativedecodeasset(native method) @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:609) @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:444) @ android.graphics.drawable.drawable.createfromresourcestream(drawable.java:1080) @ android.content.res.resources.loaddrawableforcookie(resources.java:2658) @ android.content.res.resources.loaddrawable(resources.java:2563) @ android.content.res.resources.getdrawable(resources.java:821) @ android.content.context.getdrawable(context.java:458) @ android.support.v4.content.contextcompat.getdrawable(contextcompat.java:353) @ android.support.v7.widget.appcompatdrawablemanager.getdrawable(appcompatdrawablemanager.java:201) @ android.support.v7.widget.appcompatdrawablemanager.getdrawable(appcompatdrawablemanager.java:189) @ android.support.v7.content.res.appcompatresources.getdrawable(appcompatresources.java:100) @ android.support.v7.widget.appcompatimagehelper.setimageresource(appcompatimagehelper.java:73) @ android.support.v7.widget.appcompatimageview.setimageresource(appcompatimageview.java:81) @ com.bne.terrainsadapter.onbindviewholder(terrainsadapter.java:51) @ com.bne.terrainsadapter.onbindviewholder(terrainsadapter.java:12) @ android.support.v7.widget.recyclerview$adapter.onbindviewholder(recyclerview.java:6400) @ android.support.v7.widget.recyclerview$adapter.bindviewholder(recyclerview.java:6433) @ android.support.v7.widget.recyclerview$recycler.trybindviewholderbydeadline(recyclerview.java:5377) @ android.support.v7.widget.recyclerview$recycler.trygetviewholderforpositionbydeadline(recyclerview.java:5640) @ android.support.v7.widget.gapworker.prefetchpositionwithdeadline(gapworker.java:282) @ android.support.v7.widget.gapworker.flushtaskwithdeadline(gapworker.java:336) @ android.support.v7.widget.gapworker.flushtaskswithdeadline(gapworker.java:349) @ android.support.v7.widget.gapworker.prefetch(gapworker.java:356) @ android.support.v7.widget.gapworker.run(gapworker.java:387) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5451) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)
it seem have large size of images in resources causing error when loading in adapter.
only use images of size required layout or else error cause often.
Comments
Post a Comment