简介
Preloader是一个用于异步加载数据的工具。它提供同步或者异步的获取结果回调。
适当地使用可让业务层获取数据的时间点提前。
使用例子
以简单activity跳转的例子为例,从MainActivity跳转到SubActivity。其中SubActivity的完整
显示需要发起一次请求,获取到结果后显示在中央的textView。
利用Preloader,我们可以在MainActivity发起跳转的时候开始请求,在SubActivity需要的时候将结果取出。
这样子可以把获取结果的时间点提前,起到加速显示SubActivity的作用。
代码如下所示:
- MainActivity:
PreloadTask<String> task = new PreloadTask<String>() { @Override public void run(Preloader.Result<String> result) throws Exception { try { // 模拟5秒的同步请求 Thread.sleep(5*1000); // 设置请求结果 result.set("hello world"); } catch (InterruptedException e) { throw e; } } @Override public void onCancel() { Log.d(TAG
, "onCancel() called"); } }; // 启动task,获取taskId。 int taskId = Preloader.start(task); // 传递taskId,用于获取结果。 Intent intent = new Intent(this, SubActivity.class); intent.putExtra("preload_task_id", taskId); startActivity(intent); - SubActivity:
mTextView = findViewById(R.id.textView); // get result int preloadTaskId = getIntent().getIntExtra("preload_task_id", -1); if (preloadTaskId > 0) { // 使用taskId取出Result对象 Preloader.Result<String> preloadResult = Preloader.getResult(preloadTaskId); if (preloadResult != null) { // 同步获取结果 try { // 取出结果,设置超时时间,单位毫秒 String content = preloadResult.get(1000); mTextView.setText(content); } catch (PreloadException e) { mTextView.setText("e=" + e.getMessage()); } // 异步获取结果 preloadResult.get(new Preloader.ResultListener<String>() { @Override public void onResult(String result, PreloadException e) { if (e == null) { mTextView.setText(result); } else { mTextView.setText("e=" + e.getMessage()); } } }); } // 取消预加载任务,所有正在等待的get方法都会返回timeout exception // Preloader.cancel(preloadTaskId); // Preloader.cancelAll(); }
注意事项
- 可通过PreloadTask.setGetResultTimeout设置异步获取结果的超时时间,默认为30秒。
- 如果PreloadTask.isClearWhenGetResult()==false,那么需要使用者自己调用Preloader.clear方法来释放预加载task,
否则预加载task将在第一次成功获取结果后被释放(无法再次通过Preloader.getResult取结果) - 对于同一个preloadResult对象,可多次调用get(),互不影响。
源码
https://github.com/legendmohe/Preloader
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
However, it’s essential to weigh the potential
benefits towards the inherent risks and to prioritize health and security above all else.
Consulting with knowledgeable or skilled coach earlier than initiating Dianabol use is strongly advised to make sure knowledgeable decision-making and danger mitigation strategies.
In The End, bodybuilding with Dianabol requires careful consideration, diligent monitoring,
and a commitment to accountable usage practices. By prioritizing safety, legality,
and high quality, you can confidently source anabolic
steroids on-line to assist your fitness and efficiency objectives successfully.
Dianabol is primarily used to increase muscle mass and energy.
Dianabol, also called Methandrostenolone, is a potent anabolic steroid
renowned for its capacity to accelerate muscle development and improve strength.
Nevertheless, its usage comes with inherent dangers and issues.
In this part, we’ll discover the basics to ensure you’re geared
up with important information before making a buy
order. Steroids like Danabol (Methandienone) 10 MG tablets are mainly prescribed to
athletes and bodybuilders who search muscle progress, restoration, and remedy.
Bear In Mind that accountable utilization and diligent
monitoring are key to attaining optimal outcomes while safeguarding your health and well-being.
Figuring Out the right dosage of Dianabol is essential
for achieving desired outcomes whereas minimizing adverse effects.
Dosage suggestions might vary depending on factors such as
age, gender, and health goals. Understanding the suitable dosage range and frequency is crucial for protected and efficient utilization. Guidance from knowledgeable
or skilled bodybuilder can provide personalised steering on Dianabol dosing.
Ensuring the authenticity of your dianabol buying information ensures safety
and efficacy in your bodybuilding journey. We have dianabol tablets
on the market in all the popular dosages – 5mg, 10mg and 20mg tablets.
20-30mg every day is effective for beginners, while advanced steroid customers may use up to 50mg per day.
So, the optimum every day dosage for beginners is
10mg-30mg, for professional bodybuilders ― 30mg-50mg.
In addition, the physician might recommend stacking Dianabols with other steroids, for example, with injectable Testosterone Enanthate.
You may depend on our unwavering assist
whereas medivillastore expedite your entry to essential
medical care, enhancing your vitality and emotional stability.
In US steroids we attempt to make it easier to purchase steroids on-line.
If you have any questions on purchasing Dbol, use our stay chat or our Contact Us web
page. By using zphcstore.com you affirm that you’re 21 years or
older. It additionally means that content material is revealed
only with informational causes. Willpower of the prognosis, mode of
use, dosages of lively substance should be suggested with your doctor.
The firm isn’t liable for the attainable unfavorable consequences
of the problems encountered by zphcstore.com .
As with any performance-enhancing substance, maximizing the advantages of Dianabol requires cautious planning
and execution. These tips can optimize your Dianabol experience and improve
your bodybuilding outcomes. Dbol will most frequently be used
as part of the bulk or build phase of the bike.
Users can expect to add a big quantity of water along with jumps in muscle mass and strength.
One of the simplest ways to use dbol is to start out an extended cycle.
With demand for steroids like Dbol so excessive, underground labs churn out lots of
faux and underdosed products. You need guaranteed real, pharma grade Dianabol – not a probably harmful counterfeit.
Discuss to a medical professional to know about the precise dosage and storage necessities of the medicine.
The course duration and the time when the medication takes
effect usually are not the identical for each recipient.
This dosage is for brand spanking new users aiming to construct mass and energy while
limiting side effects. Medivillastore.com give careful consideration to your basic well-being.
Whether Or Not you’re a beginner or an skilled athlete, this blog offers useful ideas and recommendation on how to keep motivated and obtain success.
From vitamin plans and workout regiments to mental
well being and physical wellness, we provide a comprehensive overview of what it takes to steer
a wholesome way of life. Safety ought to always be
paramount when incorporating dianabol gym tablets into your routine.
Here, we provide a detailed guide on dosage recommendations and cycle
length to optimize efficacy whereas minimizing antagonistic effects.