Android Droid-Fu introduction (1)

Source: Internet
Author: User

What is Droid-Fu?Droid-Fu is a general Android Application Library

The main purpose of Droid-Fu is to make Android development easier.

Isn't Droid-Fu open source enough?

Droid-Fu contains many tool classes and very easy-to-use Android components, all of which are very useful for Android applications. Droid-Fu provides support in the following fields:

Android app lifecycle, background tasks, Http message processing, remote image processing, custom Adapter... And so on. Droid is still very young and will have more exciting features in the near future!Basic knowledgeThe biggest advantage is the application he proposed.Lifecycle help class. If you are developing an Android Application and its main task is to run background tasks, such as capturing data from the web, you will certainly use Droid-Fu in your application.

Droid-Fu

The annoying AsyncTask, let's take a look at the problem of AsyncTask: first, what is AsyncTask? It is a help class for executing large sales operations. If you are developing a mobile app that needs to access the web server, you may have used it.

The basic idea is to initiate an asynchronous task. When the task thread executes the task, a beautiful progress box is displayed. When the task returns the result to the Activity, the Progress box is closed. Cool, but if the user decides to rotate the screen, the asynchronous task is still running. What should I do? rotating the current Activity on the screen will complete the entire lifecycle. Then recreate and call back the onCreate () method .)? Or when a phone call comes in and interrupts the app, Android decides to kill the app process. What should I do? Both of these actions will interrupt the activity. When you continue to use this application, the Activity will be recreated. Unfortunately, AsyncTask is still running and keeps a pointer pointing to the old Activity, because the restarted Activity is a completely different object in the memory and will execute onCreate () of the Activity (), as if Activity was started for the first time ). I'm not sure if AsyncTask will return the result to the old Activity object. If it is a weak reference, it may have been recycled.) But in any case, the new Activity will not receive the data, because it is a new Activity instance.

Now, people can say: Okay, let's do the same job again and resend the request. Yes, you can. But this is a waste. Really, it makes you feel stupid, isn't it? In addition, if you trigger a Web service request, flip the screen, and find that the request is not what you want and is flipped back, your request is sent three times parallel. Is that what you want? Probably not.

BetterAsyncTaskFortunately, Droid-Fu provided us with a solution: BetterAsyncTask! Its behavior is exactly the same as AsyncTask. In fact, this is an AsyncTask), but it does some extra work for you: First, it records the currently active instance. If the instance changes, return the released data to the new instance. In other words, you can dispatch your task and flip the screen back and forth at will. BetterAsyncTask will still return the task result to the current active instance. In other words, the task runs only once. There is a problem because BetterAsyncTask cannot find out which instance is currently active. It depends on an assistant:

DroidFuApplication. This class isApplicationIf you want to useBetterAsyncTask, Your application is derived from this class, otherwise it will not work. This is becauseDroidFuApplicationThe weak ing of the active instance is retained.BetterAsyncTaskThen, it obtains the Activity instance through your Application.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.