I have a big activity (let's call it BigActivity) where I have a lot fragments inside. From BigActivity I start another one (let's call it PainfulActivity) with an Intent the usual way. I have a fragment living inside PainfulActivity and a RecyclerView in the fragment (let's call the fragment PainfulFragment).
In my PainfulFragment I make a network call and fetch my data. I have an adapter (let's call that PainfulAdapter) that I subclassed from RecyclerView.Adapter.
And successfully wired up everything. Data is drawn on the screen and no problem until now. When I scroll RecyclerView, it leaves residue or glitch whatever you call it.
I tried to populate my PainfulFragment in my BigActivity in one of the fragment containers, and everything works fine. So I know my fragment, adapter etc.. is working fine.
I tried to populate one of the fragments in PainfulActivity that normally lives in BigActivity, and I have the same problem, RecyclerView glitches again on scroll.
I was thinking perhaps it could be a memory problem, and observed the Profiler tool in Android Studio, however there is nothing unusual there neither.
Did anyone come across with such a problem?
Related
I am developing an android social media type application, where I have a multiple tab activity. The tabs are fragments using viewpager.I have a home screen with a recycler view. The post have images on them. I am having memory problem with the recyclerview for post. I am using firebase as a database if thats helpful. To load the imageview I am using glide and I am doing diskcache and skipping the memory caches.
Issues I am having are
When too many posts are loaded, recyclerview becomes slow and laggy (I know that there are other post with this but couldnt really found anything helpful).
When I click on a username from the post, a new profile activity starts which also have all the posts from that user, I am trying to find a way clear the homepage tab recyclerview memory but struggleing with how to.
To solve the first problem, I have set up an onscrolllistner that loads 10 new post everytime you are near the end of the post list. The recycler view adapter currently loads 20 items initially and then so on.but I am not sure how to clear the old posts in an efficient way since I want the user to be able to scroll up.
To solve the second problem, In the homescreen fragment, when I launch the new activity, the onPause() function gets called. In the onpause() function I tried setting the list to empty, recyclerview adapter to null, recylerview to null but nothing has worked. In the android profiler tool, I see that I am using 200 mb memory, and when I start the new activity, it adds another 100 mb or so. I tried manual garbage collections but it doesnt work either. To be specific, native memory jumps up in the profiler. Ive tested and made sure that was only because of the images in the recyclerview.
I am not sure why when I set recyclerview, adapter and the post list to null, why the images from posts are still being held in the memory.
Glide caches the images
To load multiple post check paging library
When moving to detail fragment and clearing the reacyclerview of home fragment , I would not recommend this as next time user switches to home tab ,the user will not have previous state saved which he left previously.
I have a Android app that shows lots of real-time data jammed onto one large scrolling activity.
Now i want to split it up into two simpler screens using fragments, where only one fragment may be on the screen at any one time.
I read up a whole lot on fragments and watched several videos, but before i start ripping up my code to convert it to fragments i wanted to know the following.
If i create two fragments A and B, then while showing fragment B, data comes in for fragment A. Can the controlling activity still communicate with fragment A giving it data even though its off screen? OR do i have to save the data somewhere and then when the user switches to fragment A then I give fragment A the data to be shown, while saving incoming data for fragment B which will now be off screen?
The problem is that right now im not saving any data because everything is on one screen, so as data come in i just displayed it, but if i switch to using fragments i dont know if i can do the same thing by passing the data to the fragments even if they are not on screen at the same time.
Thanks.
If you retrieve your data with multiple asynchronous requests in your Activity, you may create a fragment for each of them and move related retrieval operation into that fragment (probably to oncreateView() method). Then, you can use ViewPager (probably with TabLayout) in the parent Activity to be able to use all those fragments. Therefore, your Activity only deals with setting the ViewPager and leave the rest to fragments.
ViewPager shows one page at a time but it can initialize other fragments as well, even before they are shown. You can use ViewPager's setOffscreenPageLimit() method to increase that range.
In case you need a communication channel between fragments and the activity, you may create callback mechanisms, as described here.
Basically what the title says. I'm trying to start a ViewPager activity when a user clicks a RecyclerView item. I'm not having problems here, that works fine. The goal is to go from a grid based gallery to viewpager gallery. I'm also trying to send the List<> of data which is loaded over the network. This is where I'm having a lot of trouble. The data is sent through a singleton because it's too large to send through intent and if opened in the new activity too quickly upon app startup, more data is loaded in the original activity (Even if Call is cancelled, using Retrofit2 btw) and I need to notify the adapter, which I have a listener that does.
Another crash that is common is a null pointer when reading an item in viewpager activity, which doesn't make sense to me because the item is not null in the original activity before sending, but if I wait a few seconds it is not null. Some of the code pertaining to my issue can be found here, a question I asked yesterday with a solution I could not successfully implement.
Please point me in the right direction for starting a ViewPager of the same dataset from a RecyclerView, thanks
When you are "sending" feed data to the view pager activity, use a shallow copy of the list instead of directly referencing it as shown below
DataTransferer.get().storeItems(new ArrayList(feed));
This should prevent IllegalStateException raised by feed being updated on your RecyclerView activity.
I have a performance problem.
So I'm writing a chat application and I have a ViewPager with Fragments in it for each separate chat, the ViewPager lives in ChatActivity, and the messages in the Fragments are displayed via a simple ListView.
Everything is smooth as long as I "minimize" my application. When the app is minimized, and I receive, say just 10 messages during that time, and return back to the activity, there is a noticeable delay (e.g. the standard Android Application restore animation does not play). If I minimize the app again, and restore it instantly, the delay is completely gone (assuming no new messages arrived).
There seems to be no correlation in the performance to the amount of new messages that have arrived: whether there are 10 or 500 new messages, the delay is the same.
I receive messages from a Socket, pass them to the Chat object, which simply passes them to the ChatFragment, which just uses listView.post() to post them into the ListView.
My ChatFragment and ListView's adapter are pretty trivial so I don't post them here, the messages are stored in an ArrayList in the Chat object (the adapter just pulls them from there).. I'm really not doing anything "fancy".
To put it simply, when my Activity (and the Fragments in it) are paused, and new data is posted to the ListView, the ListView (I assume) has to do "more work at once" when the Fragment is resumed and the ListView is "refreshed".
This might be a bit vague without code, but perhaps someone can tell me if my principle is at least right (i.e. simply post() the messages to the adapter, regardless if the Activity and Fragment are visible to the user?).
If anyone has any ideas what might cause this delay, I'd be very grateful.
My intuition about new messages and the ListView problem was completely wrong! What caused the slowdown was that I have a launcher activity that launches the previously visible activities or displays itself if there isn't one. Instead of calling finish() in the onCreate() of it, I simply called return! This caused the activity to go on with its lifecycle, doing whatever it does behind the scenes, causing the slowdown.
Hi i am working with android , and i have a problem with the activity stack. As i know, when someone uses the back button, reload the back activity. But in the case i have many layouts shown from one activity, how can i go back to them.
Here is the deal, i am using a listview filled with categories, and when i press an item, i reuse the activity and the layout, to show its subcategories. So what i need is to came back no to the back activity, not to the back layout, but to the back "state".
Well, the idea is simple, first i show all the categories with no parent, then when i pressed an item, i show its subcategories.
The easiest way is creating two Activities - for categories and for subcategories. If you try to implement all the logic in a single Activity you won't earn nothing and just end up totally confused. Using Activities simplifies things a lot just because it handles problems such as yours. Hope this helps.
Check out Fragments, they are the stepping stone between a view and an activity. An activity can have multiple fragments and will manage their back stack (if you tell it to).
http://developer.android.com/guide/components/fragments.html
You'll have to use the support library to used them on pre honeycomb devices.