Pre-load data before Activity opens, and display data on UI after UI initialization. Speedup Activity launch
You can start a PreLoader everywhere and start to listen data which loaded by the PreLoader with preLoaderId
if DataLoader.loadData() is not completed, then DataListener.onDataArrived() will be called after the data load is completed
if DataLoader.loadData() is completed, then DataListener.onDataArrived() called immediately
Continuous optimization, welcome watch, star!
Pre-load data in Application.onCreate for HomePageActivity to reduce the user waiting time in HomePageActivity initialization
Pre-load data before context.startActivity(), and display data after activity UI are initialized
Pre-load data for complex UI Activity (UI initialization cost too much time)
Pre-load data for next page of ListView/RecyclerView before pull to load more
support network data, network images, local images, database queries, and file I/O
support for cross-activity pre-loading
support pull-down refresh (DataLoader reloads once, after loading completes, callback for all DataListener)
supports custom thread-pool
support one loader (DataLoader) for multiple listeners (DataListener)
support multiple preload tasks for an Activity
support for add/remove listener dynamically
- add dependencies in build.gradle
dependencies{compile 'com.billy.android:pre-loader:x.x.x' }- start a pre-load
intpreLoaderId = PreLoader.preLoad(newLoader()); Intentintent = newIntent(this, PreLoadBeforeLaunchActivity.class); intent.putExtra("preLoaderId", preLoaderId); startActivity(intent); //DataLoader, mock as load data from networkclassLoaderimplementsDataLoader<String>{@OverridepublicStringloadData(){try{Thread.sleep(600)} catch (InterruptedExceptionignored){} return"data from network server"} }- Listen data after UI initialization in Activity/Fragment/View
PreLoader.listenData(preLoaderId, newListener()); //after data load completed,DataListener.onDataArrived(...) will be called to process dataclassListenerimplementsDataListener<String>{@OverridepublicvoidonDataArrived(Stringdata){Toast.makeText(activity, data, Toast.LENGTH_SHORT).show()} }- Refresh data: DataLoader.loadData() will be called, and DataListener.onDataArrived() will be called for all listeners
PreLoader.refresh(preLoaderId);- Destroy the PreLoader object if you do not need it(eg. Activity is destroyed)
PreLoader.destroy(preLoaderId);CC framework comes with AOP at the component level: when component is calling for start an activity, you can start a pre-load for it. So, it is not need to do pre-load work in every place where you want to start the Activity.
- define a component for open the activity
publicclassComponentAimplementsIComponent{@OverridepublicStringgetName(){return"demo.ComponentA"} @OverridepublicbooleanonCall(CCcc){intpreLoaderId = PreLoader.preLoad(newLoader()); Intentintent = newIntent(this, PreLoadBeforeLaunchActivity.class); intent.putExtra("preLoaderId", preLoaderId); startActivity(intent); CC.sendCCResult(cc.getCallId(), CCResult.success()); returnfalse} }call that component by CC to open activity
// pre-load is needless here, the logistic of component are all inside that component itselfCC.obtainBuilder("demo.ComponentA").build().call();


