Android development and android Development Environment Construction

Source: Internet
Author: User

Android development and android Development Environment Construction
What is ActivityLifecycleCallbacks?

  • The Application provides a set of callback methods for developers to centrally process Activity lifecycle events.
Why is ActivityLifecycleCallbacks used?
  • In the past, if you need to monitor the Activity's lifecycle Event code, you may do this by rewriting the onResume () of each Acivity, and then making statistics and processing:
    @ Overrideprotected void onResume () {super. onResume (); // TODO Processing and Statistics Code Log. v (TAG, "onResume"); Logger. v (TAG, "onResume"); Logging. v (TAG, "onResume ");...}

  • ActivityLifecycleCallbacks interface callback can simplify this tedious process and perform unified processing in a class.
How to Use ActivityLifecycleCallbacks?
  • Android. app. Application. ActivityLifecycleCallbacks
  • Requires API 14 + (Android 4.0 +)
  • Inherit Application
    public class BaseApplication extends Application

  • Use Custom Application in AndroidManifest
    <application android:name=".global.BaseApplication"

  • Override the onCreate () method of the Application, or call the Application. registerActivityLifecycleCallbacks () method within the construction method without parameters of the Application, and implement the ActivityLifecycleCallbacks Interface

    public void onCreate() {  super.onCreate();  this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {     @Override    public void onActivityStopped(Activity activity) {        Logger.v(activity, "onActivityStopped");    }     @Override    public void onActivityStarted(Activity activity) {        Logger.v(activity, "onActivityStarted");    }     @Override    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {        Logger.v(activity, "onActivitySaveInstanceState");    }     @Override    public void onActivityResumed(Activity activity) {        Logger.v(activity, "onActivityResumed");    }     @Override    public void onActivityPaused(Activity activity) {        Logger.v(activity, "onActivityPaused");    }     @Override    public void onActivityDestroyed(Activity activity) {        Logger.v(activity, "onActivityDestroyed");    }     @Override    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {        Logger.v(activity, "onActivityCreated");    }  });};

  • Running result (Logcat log)

    10-21 14:32:57.722: V/WelcomeActivity(8085): onActivityCreated10-21 14:32:57.762: V/WelcomeActivity(8085): onActivityStarted10-21 14:32:57.762: V/WelcomeActivity(8085): onActivityResumed10-21 14:32:59.164: V/WelcomeActivity(8085): onActivityPaused10-21 14:32:59.194: V/MainActivity(8085): onActivityCreated10-21 14:32:59.224: V/MainActivity(8085): onActivityStarted10-21 14:32:59.224: V/MainActivity(8085): onActivityResumed10-21 14:32:59.735: V/WelcomeActivity(8085): onActivityStopped10-21 14:32:59.735: V/WelcomeActivity(8085): onActivityDestroyed10-21 14:33:06.502: V/MainActivity(8085): onActivityPaused10-21 14:33:06.612: V/MainActivity(8085): onActivityStopped10-21 14:33:06.612: V/MainActivity(8085): onActivityDestroyed

Extended usage of ActivityLifecycleCallbacks
  • This preliminary study only attempts to use the Log tool for a brief test. This method may greatly reduce the amount of inserted code and improve the efficiency to meet complicated statistics or debugging requirements.

  • The API only provides callback for this interface in version 14 and earlier. How can I use this interface in Android 4.0 or lower systems?

  • The API only sets aside interface callback for the lifecycle events of the preceding activities, and may no longer be able to meet the requirements of the transition to use Fragment. How can I apply LifecycleCallbacks in a larger scope?

Build an Android Development Environment

2. Configure ADT (Figure 3.1 to figure 3.10)
Android project development can be performed only when the ADT plug-in and Android SDK are configured.
ADT Configuration:
Step 1: Open eclipse, double-click eclipse.exe, and click OK, as shown in Figure 3.1 to Figure 3.4;
Step 2: In eclipse, select "help-> Install New Software"-> click "add"-> select “archive..htm, select the adt-0.9.1.zip file, and click "OK"-> select "Developer Tools ", click "Next"-> "Finished"-> finish, select the terms of acceptance, and click "Finished" until the process is completed. After completion, eclipse is restarted. Figure 3.5 to figure 3.10;
3. Configure the Android SDK (Figure 3.1 to figure 3.14)
In eclipse, select "Window-> Preferences"-> "Android" in sequence. The Window shown in Figure 3.12 appears, close the warning window-> select the android sdk directory (decompressed by), 3.13, and click OK-> In Figure 3.14, click "Apply" and click "OK ", after the configuration is complete, return to the eclipse initial interface.
I have a document for you.
I have just configured the ADT version. If it is relatively high, you need to obtain an avd.

Build an Android Development Environment

2. Configure ADT (Figure 3.1 to figure 3.10)
Android project development can be performed only when the ADT plug-in and Android SDK are configured.
ADT Configuration:
Step 1: Open eclipse, double-click eclipse.exe, and click OK, as shown in Figure 3.1 to Figure 3.4;
Step 2: In eclipse, select "help-> Install New Software"-> click "add"-> select “archive..htm, select the adt-0.9.1.zip file, and click "OK"-> select "Developer Tools ", click "Next"-> "Finished"-> finish, select the terms of acceptance, and click "Finished" until the process is completed. After completion, eclipse is restarted. Figure 3.5 to figure 3.10;
3. Configure the Android SDK (Figure 3.1 to figure 3.14)
In eclipse, select "Window-> Preferences"-> "Android" in sequence. The Window shown in Figure 3.12 appears, close the warning window-> select the android sdk directory (decompressed by), 3.13, and click OK-> In Figure 3.14, click "Apply" and click "OK ", after the configuration is complete, return to the eclipse initial interface.
I have a document for you.
I have just configured the ADT version. If it is relatively high, you need to obtain an avd.

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.