FirebaseUI的FirebaseRecyclerAdapter

时间:2018-06-11 15:21:22

标签: android firebase firebase-realtime-database

我们注意到我们的RecyclerAdapter至少需要3.5秒才能从我们的firebase实时数据库加载数据并显示数据。我们正试图找出导致此延迟的原因,或者它是否是SDK问题。我们正在使用firebase-ui-database:3.1.0来支持API 26而不会被编译器大吼。

Query query = mEvalRef.orderByChild(IS_DRAFT_KEY).equalTo(true);
FirebaseRecyclerOptions<Assessment> options = new 
FirebaseRecyclerOptions.Builder<Assessment>()
            .setQuery(query, Assessment.class)
            .build();

    mRecyclerView = (RecyclerView) findViewById(R.id.draft_recycler_view);
    mRecyclerView.setHasFixedSize(false);
    mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setReverseLayout(true);
    mLayoutManager.setStackFromEnd(true);
    mRecyclerView.setLayoutManager(mLayoutManager);

    mRecyclerAdapter = new FirebaseRecyclerAdapter<Assessment, ReusableViewHolder>(options) {
        ReusableViewHolder.ClickListener mClickListener;

        @Override
        protected void onBindViewHolder(ReusableViewHolder holder, final int position, Assessment model) {
            Log.d("ViewHolder Info", "ViewHolder Bound");
            holder.companyName.setText(model.getCompany());
            holder.industryName.setText(model.getIndustry());
            holder.locationName.setText(model.getLocation());
            holder.ownerName.setText(model.getOwnerName());
            holder.dateCreated.setText(model.getLocalizedDate());

            holder.mView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(ViewDraftsActivity.this, EditDraftActivity.class);
                    String selectedItem = mRecyclerAdapter.getRef(position).getKey();
                    intent.putExtra("assessment_key", selectedItem);
                    startActivity(intent);
                    overridePendingTransition(R.transition.slide_in_right, R.transition.slide_out_left);
                }
            } );
        }

        @Override
        public ReusableViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            Log.d("ViewHolder Info", "ViewHolder Inflated");
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.completed_and_drafts_list_item, parent, false);
            return new ReusableViewHolder(view);
        }

        @Override
        public void onError(DatabaseError e) {
            Snackbar.make(contentView,
                    "There was an error fetching the list of Draft Assessments. " +
                            "Please check your internet connection",
                    Snackbar.LENGTH_LONG);
        }
    };

    mRecyclerView.setAdapter(mRecyclerAdapter);

我们的数据已被扁平化和非规范化,并且开始时相对简单,因此我们知道它不是由于这一点。这是日志:

06-11 14:54:24.958 8165-8165/com.[my_app_sig] D/ViewHolder Info: Activity Created
06-11 14:54:24.978 8165-8279/com.[my_app_sig] I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
Selected remote version of com.google.android.gms.firebase_database, version >= 6
06-11 14:54:24.984 8165-8270/com.[my_app_sig] D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=QuickCheckHomeActivity, firebase_previous_id(_pi)=-8222266655409448112, firebase_screen_class(_sc)=ViewDraftsActivity, firebase_screen_id(_si)=-8222266655409448111}]
06-11 14:54:25.021 1439-1439/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 12587008
06-11 14:54:25.037 1439-1439/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 12587008
06-11 14:54:25.060 1439-1439/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 12587008
06-11 14:54:25.126 8165-8270/com.[my_app_sig] D/FA: Connected to remote service
06-11 14:54:25.135 8165-8214/com.[my_app_sig] D/EGL_emulation: eglMakeCurrent: 0x9fc86080: ver 2 0 (tinfo 0x9fc83da0)
06-11 14:54:25.147 8165-8170/com.[my_app_sig] I/zygote: Do full code cache collection, code=249KB, data=141KB
06-11 14:54:25.149 8165-8170/com.[my_app_sig] I/zygote: After code cache collection, code=247KB, data=103KB
06-11 14:54:25.153 8165-8170/com.[my_app_sig] I/zygote: Do partial code cache collection, code=248KB, data=111KB
06-11 14:54:25.154 8165-8170/com.[my_app_sig] I/zygote: After code cache collection, code=248KB, data=111KB
Increasing code cache capacity to 1024KB
06-11 14:54:25.157 8165-8279/com.p3_[my_app_sig] W/CursorWindow: Window is full: requested allocation 7045 bytes, free space 120 bytes, window size 2097152 bytes
06-11 14:54:25.157 1973-1995/system_process I/ActivityManager: Displayed com.[my_app_sig]/com.[my_app_sig].ViewDraftsActivity: +234ms
06-11 14:54:25.232 8165-8279/com.[my_app_sig] W/CursorWindow: Window is full: requested allocation 7045 bytes, free space 1600 bytes, window size 2097152 bytes
06-11 14:54:25.327 8165-8279/com.[my_app_sig] I/chatty: uid=10085(u0_a85) FirebaseDatabas identical 3 lines
06-11 14:54:25.348 8165-8279/com.[my_app_sig] W/CursorWindow: Window is full: requested allocation 7045 bytes, free space 1600 bytes, window size 2097152 bytes
06-11 14:54:25.372 8165-8279/com.[my_app_sig] W/CursorWindow: Window is full: requested allocation 7045 bytes, free space 1744 bytes, window size 2097152 bytes
06-11 14:54:25.398 8165-8279/com.[my_app_sig] W/CursorWindow: Window is full: requested allocation 7045 bytes, free space 1532 bytes, window size 2097152 bytes
06-11 14:54:25.422 8165-8279/com.[my_app_sig] W/CursorWindow: Window is full: requested allocation 7050 bytes, free space 1380 bytes, window size 2097152 bytes
06-11 14:54:25.451 8165-8279/com.[my_app_sig] W/CursorWindow: Window is full: requested allocation 14078 bytes, free space 10984 bytes, window size 2097152 bytes
06-11 14:54:25.466 1449-1449/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
06-11 14:54:26.199 2680-8271/com.google.android.gms D/FA-SVC: Updated lifetime engagement user property with value. Value: 69566662
06-11 14:54:26.215 2680-8271/com.google.android.gms D/FA-SVC: Uploading events. Elapsed time since last upload attempt (ms): 1011
06-11 14:54:26.345 8165-8176/com.[my_app_sig] I/zygote: Background concurrent copying GC freed 255572(8MB) AllocSpace objects, 82(1720KB) LOS objects, 11% free, 44MB/50MB, paused 442us total 112.314ms
06-11 14:54:26.582 8165-8176/com.[my_app_sig] I/zygote: Background concurrent copying GC freed 328516(11MB) AllocSpace objects, 103(2MB) LOS objects, 10% free, 53MB/59MB, paused 447us total 103.473ms
06-11 14:54:26.724 8165-8176/com.[my_app_sig] I/zygote: Background concurrent copying GC freed 389527(13MB) AllocSpace objects, 122(2MB) LOS objects, 9% free, 58MB/64MB, paused 475us total 119.474ms
06-11 14:54:26.881 8165-8176/com.[my_app_sig] I/zygote: Background concurrent copying GC freed 411814(14MB) AllocSpace objects, 128(2MB) LOS objects, 8% free, 63MB/69MB, paused 470us total 133.975ms
06-11 14:54:27.054 8165-8176/com.[my_app_sig] I/zygote: Background concurrent copying GC freed 444470(15MB) AllocSpace objects, 136(2MB) LOS objects, 7% free, 71MB/77MB, paused 457us total 149.379ms
06-11 14:54:27.217 8165-8176/com.[my_app_sig] I/zygote: Background concurrent copying GC freed 507592(17MB) AllocSpace objects, 156(3MB) LOS objects, 7% free, 76MB/82MB, paused 478us total 140.518ms
06-11 14:54:27.305 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.315 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound
06-11 14:54:27.322 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.325 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound
06-11 14:54:27.328 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.332 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound
06-11 14:54:27.335 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.339 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound
06-11 14:54:27.342 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.345 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound

清理,以便您可以看到与ViewHolder通胀相比的活动创建:

06-11 14:54:24.958 8165-8165/com.[my_app_sig] D/ViewHolder Info: Activity Created
06-11 14:54:27.305 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.315 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound
06-11 14:54:27.322 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.325 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound
06-11 14:54:27.328 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.332 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound
06-11 14:54:27.335 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.339 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound
06-11 14:54:27.342 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Inflated
06-11 14:54:27.345 8165-8165/com.[my_app_sig] D/ViewHolder Info: ViewHolder Bound

有关改善此表现的任何想法都会很棒,如果您需要澄清任何事情,请告诉我们!

0 个答案:

没有答案