0

I am new to android Recycle view, I have following code in place which works perfectly fine, but only problem I have that it loads really slow for the 1st time my activity loads , and after the 1st time rest all the time same activity loads faster with no delay.

 holder.mImgView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //String animal = mDataSet.get(position);
            final Course course1 = mDataSet.getItem(position);
            String animal = course1.getTitle();
            Toast.makeText(mContext, animal, Toast.LENGTH_SHORT).show();

            Intent intent = new Intent(mContext, DetailActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setType("text/plain");
            intent.putExtra(COURSE_TITLE, course.getTitle());
            intent.putExtra(COURSE_DESC, course.getDescription());
            intent.putExtra(COURSE_NO, course.getCourseNumber());

            mContext.startActivities(new Intent[]{intent});

I noted that, before the new activity starts (out of the activity class) it does too many things in the log, this might give you some hint. Log can be seen here:

01-12 22:30:48.500 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 11.654ms   
01-12 22:31:06.870 27490-27490  com.example.android.recycle D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN  
01-12 22:31:07.550 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 351.452ms  
01-12 22:31:08.830 27490-27490  com.example.android.recycle D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered!  
01-12 22:31:09.230 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 28.800ms   
01-12 22:31:09.440 27490-27490  com.example.android.recycle D/PhoneWindow: *FMB* installDecor mIsFloating : false  
01-12 22:31:09.440 27490-27490  com.example.android.recycle D/PhoneWindow: *FMB* installDecor flags : -2139029248  
01-12 22:31:10.270 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 71.765ms   
01-12 22:31:10.690 27490-27505  com.example.android.recycle W/art: Suspending all threads took: 119.470ms  
01-12 22:31:10.710 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 14.256ms   
01-12 22:31:10.710 27490-27505  com.example.android.recycle I/art: Background sticky concurrent mark sweep GC freed 1727(277KB) AllocSpace objects, 3(113KB) LOS objects, 0%    free, 49MB/49MB, paused 124.064ms total 318.834ms
01-12 22:31:10.910 27490-27505  com.example.android.recycle I/art: Background partial concurrent mark sweep GC freed 587(51KB) AllocSpace objects, 1(10MB) LOS objects, 29% free, 38MB/54MB, paused 6.012ms total 188.648ms
01-12 22:31:12.560 27490-27490  com.example.android.recycle W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contain    s no resources.
01-12 22:31:12.560 27490-27490  com.example.android.recycle W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
01-12 22:31:12.860 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 159.304ms  
01-12 22:31:13.270 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 59.209ms   
01-12 22:31:13.720 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 18.736ms   
01-12 22:31:13.750 27490-27490  com.example.android.recycle W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc 
01-12 22:31:13.760 27490-27490  com.example.android.recycle W/AudioCapabilities: Unsupported mime audio/evrc   
01-12 22:31:13.780 27490-27490  com.example.android.recycle W/AudioCapabilities: Unsupported mime audio/qcelp  
01-12 22:31:13.790 27490-27490  com.example.android.recycle W/AudioCapabilities: Unsupported mime audio/mpeg-L1
01-12 22:31:13.800 27490-27490  com.example.android.recycle W/AudioCapabilities: Unsupported mime audio/mpeg-L2
01-12 22:31:13.830 27490-27490  com.example.android.recycle W/AudioCapabilities: Unsupported mime audio/x-ms-wma   
01-12 22:31:13.850 27490-27490  com.example.android.recycle W/AudioCapabilities: Unsupported mime audio/x-ima  
01-12 22:31:13.860 27490-27490  com.example.android.recycle W/AudioCapabilities: Unsupported mime audio/qcelp  
01-12 22:31:13.870 27490-27490  com.example.android.recycle W/AudioCapabilities: Unsupported mime audio/evrc   
01-12 22:31:13.900 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/wvc1   
01-12 22:31:13.910 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/x-ms-wmv   
01-12 22:31:13.910 27490-27490  com.example.android.recycle W/Utils: could not parse size range '64x64-1920X1080'  
01-12 22:31:13.940 27490-27490  com.example.android.recycle W/VideoCapabilities: Unrecognized profile/level 32768/2 for video/mp4v-es  
01-12 22:31:13.950 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/wvc1   
01-12 22:31:13.950 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/x-ms-wmv   
01-12 22:31:13.950 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/x-ms-wmv7  
01-12 22:31:13.960 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/x-ms-wmv8  
01-12 22:31:13.960 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/mp43   
01-12 22:31:13.970 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/sorenson   
01-12 22:31:13.980 27490-27490  com.example.android.recycle W/VideoCapabilities: Unsupported mime video/mp4v-esdp  
01-12 22:31:14.010 27490-27490  com.example.android.recycle I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es   
01-12 22:31:14.060 27490-27490  com.example.android.recycle I/ACodec:  [] Now uninitialized
01-12 22:31:14.070 27490-29735  com.example.android.recycle I/OMXClient: Using client-side OMX mux.
01-12 22:31:14.120 27490-29735  com.example.android.recycle I/ACodec: [OMX.qcom.video.decoder.avc] Now Loaded  
01-12 22:31:14.240 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 13.783ms   
01-12 22:31:15.230 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 25.681ms   
01-12 22:31:16.190 27490-27490  com.example.android.recycle I/WebViewFactory: Loading com.google.android.webview version 46.0.2490.76 (code 249007600) 
01-12 22:31:16.420 27490-27490  com.example.android.recycle I/cr.library_loader: Time to load native libraries: 28 ms (timestamps 8250-8278)   
01-12 22:31:16.420 27490-27490  com.example.android.recycle I/cr.library_loader: Expected native library version number "46.0.2490.76", actual native library version number    "46.0.2490.76"
01-12 22:31:16.460 27490-27490  com.example.android.recycle V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {60565} 
01-12 22:31:16.460 27490-27490  com.example.android.recycle I/cr.library_loader: Expected native library version number "46.0.2490.76", actual native library version number    "46.0.2490.76"
01-12 22:31:16.530 27490-27490  com.example.android.recycle I/chromium: [INFO:library_loader_hooks.cc(118)] Chromium logging enabled: level = 0, default verbosity = 0 
01-12 22:31:16.600 27490-27490  com.example.android.recycle I/cr.BrowserStartup: Initializing chromium process, singleProcess=true 
01-12 22:31:16.670 27490-27490  com.example.android.recycle E/SysUtils: ApplicationContext is null in ApplicationStatus
01-12 22:31:17.330 27490-27490  com.example.android.recycle E/chromium: [ERROR:browser_gpu_channel_host_factory.cc(258)] Failed to init browser shader disk cache. 
01-12 22:31:17.390 27490-29841  com.example.android.recycle W/cr.media: Requires BLUETOOTH permission  
01-12 22:31:17.570 27490-27490  com.example.android.recycle E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
01-12 22:31:18.250 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 36.905ms   
01-12 22:31:18.580 27490-27490  com.example.android.recycle I/Ads: Starting ad request.
01-12 22:31:18.740 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 19.859ms   
01-12 22:31:18.960 27490-27490  com.example.android.recycle I/Choreographer: Skipped 605 frames!  The application may be doing too much work on its main thread.   
01-12 22:31:19.010 27490-27490  com.example.android.recycle D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null 
01-12 22:31:19.010 27490-27490  com.example.android.recycle D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
01-12 22:31:19.240 27490-27490  com.example.android.recycle D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered!  
01-12 22:31:19.740 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 20.142ms   
01-12 22:31:19.810 27490-27490  com.example.android.recycle I/Choreographer: Skipped 46 frames!  The application may be doing too much work on its main thread.
01-12 22:31:20.500 27490-27490  com.example.android.recycle V/ActivityThread: updateVisibility : ActivityRecord{3eb83853 token=android.os.BinderProxy@3ce90fd2 {com.example.    android.recycle/com.example.android.prarthana.Main2Activity}} show : false
01-12 22:31:20.770 27490-27490  com.example.android.recycle I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@297d0eeb time:226642629 
01-12 22:31:34.890 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 131.854ms  
01-12 22:31:35.190 27490-27490  com.example.android.recycle I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContents    ClientAdapter$WebResourceErrorImpl>
01-12 22:31:35.190 27490-27490  com.example.android.recycle I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContents    ClientAdapter$WebResourceErrorImpl>
01-12 22:31:35.260 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 5.297ms
01-12 22:31:35.570 27490-27490  com.example.android.recycle I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActi    onModeCallback>
01-12 22:31:35.570 27490-27490  com.example.android.recycle I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActi    onModeCallback>
01-12 22:31:35.660 27490-27490  com.example.android.recycle W/art: Attempt to remove local handle scope entry from IRT, ignoring   
01-12 22:31:35.760 27490-27490  com.example.android.recycle W/AwContents: onDetachedFromWindow called when already detached. Ignoring  
01-12 22:31:35.810 27490-27490  com.example.android.recycle W/art: Attempt to remove local handle scope entry from IRT, ignoring   
01-12 22:31:35.810 27490-27490  com.example.android.recycle W/art: Attempt to remove local handle scope entry from IRT, ignoring   
01-12 22:31:36.770 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 6.153ms
01-12 22:31:37.050 27490-27490  com.example.android.recycle W/cr.BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 27490
01-12 22:31:39.020 27490-27490  com.example.android.recycle I/Ads: Scheduling ad refresh 60000 milliseconds from now.  
01-12 22:31:39.260 27490-27490  com.example.android.recycle W/art: Attempt to remove local handle scope entry from IRT, ignoring   
01-12 22:31:39.270 27490-27490  com.example.android.recycle W/AwContents: onDetachedFromWindow called when already detached. Ignoring  
01-12 22:31:39.330 27490-27490  com.example.android.recycle W/art: Attempt to remove local handle scope entry from IRT, ignoring   
01-12 22:31:39.330 27490-27490  com.example.android.recycle W/art: Attempt to remove local handle scope entry from IRT, ignoring   
01-12 22:31:39.440 27490-27490  com.example.android.recycle I/Ads: Ad finished loading.
01-12 22:31:39.450 27490-27490  com.example.android.recycle I/Choreographer: Skipped 37 frames!  The application may be doing too much work on its main thread.
01-12 22:31:39.750 27490-27490  com.example.android.recycle W/cr.BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 27490
01-12 22:31:39.850 27490-27490  com.example.android.recycle I/chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doub    leclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
01-12 22:31:39.860 27490-27490  com.example.android.recycle I/chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/ma    ds/static/mad/sdk/native/sdk-core-v40-loader.html (0)
01-12 22:31:40.000 27490-27490  com.example.android.recycle I/chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/ma    ds/static/mad/sdk/native/sdk-core-v40-loader.html (0)
01-12 22:31:49.300 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 7.751ms
01-12 22:31:50.340 27490-27497  com.example.android.recycle W/art: Suspending all threads took: 45.500ms

Please give me some pointer to speedup this.

Thanks.

Chris Stillwell
  • 10,266
  • 10
  • 67
  • 77
Raj
  • 75
  • 1
  • 7
  • Make sure your onclick listener is in the view holder class, not where data is bound, otherwise a new click listener is created for every position. Have a look here: http://stackoverflow.com/a/30285361/4252352 – Mark Jan 12 '16 at 17:35

1 Answers1

0

I think the problem is not in the recycler view, but in the activity you are starting. The log contains a lot info about initializing some media playback or web view, and it may be quite expensive. If it is done in the main thread, it can delay showing the view and look like the click takes long time.

There is also some garbage collection which takes in total 2 seconds. It looks suspicious, but your log spans a lot longer, so it may be not the main issue.

If I were you, I would:

  1. Add activity lifecycle logging to find out exactly which callback is problematic
  2. Use traceview to find method which execution takes longest time
Zbigniew Malinowski
  • 1,034
  • 1
  • 9
  • 22
  • I agree with you to some extent. but I wonder why it takes time only first time not the send time I load the activity . – Raj Jan 14 '16 at 07:53
  • I tried commenting out the adMob code , and it seems to be working fine. looks like admob is taking time to generate the view and resulting in total time increase. Not sure how can I can use the admob code now , so it doesn't hamper the performance . – Raj Jan 14 '16 at 10:50
  • From the log you've sent there is no way to guess it - next time please use more specific logging or try to narrow the problem, we don't have crystal balls here ;) – Zbigniew Malinowski Jan 14 '16 at 11:30