Application

For each application without specifying an application, the system helps generate an instance of the application. An Application represents the current Application that is usually done using Application

1. Share data 2. Recycle to facilitate exit 3Copy the code

If you want to implement the above three points, you generally need to implement the singleton pattern, note:

1. Private constructors not allowed, initialized by the system 2. Objects not allowed, created by the system 3. In the onCreate life cycle, bind the Instance object to this.Copy the code

Activity

One of the core objects of Android is that all the functions for interacting with the user (display, manipulation) are here

Android: screenOrientation specify the current Activity show the android: such as somehow the exported whether to allow the Activity by other programs call android: launchMode Set the standard, singleTop, Sin gleTask, and singleInstance startup modes for the ActivityCopy the code

The life cycle

  1. Create oncreate-onstart-onResume
  2. Death onPause – onStop – onDestroy

The condition of being covered:

  1. Completely override onpause-onstop Run onRestart – onStart – onResume
  2. Blocking part of onPause runs onResume
  3. The collected activity is killed, no more methods are executed, and when it comes back, it’s no longer the activity. Create another activity

Create the Activity

2. Override the onCreate method and set the layout (setContentView) 3. Register the activity under the Application node in the manifest (name= create activity)Copy the code

The Activity of the jump

Intent intent = new Intent(this, OtherActivity.class);
startActivity(intent);
Copy the code

LogCat interface

If no, run: window-show view-other-android-logcat 1. Filter, usually by application package name and Tag. 2. Text filter. The filtering levels V, D, I, W, and E correspond to five logs of the Log classCopy the code

Shut off the Activity

Call the Activity's Finish () method to close the current Activity. Note: If the current Activity is not the main Activity, the finish() method returns the Activity to which it was called; otherwise, it returns to the main screen.Copy the code

Use Toast in activities

Toast is an excellent reminder provided by Android. It can be used in an application to notify users of short messages that disappear automatically after a period of time and do not take up any screen space. Let's try using Toast in an activity. Toast.maketext (mainactivity.this, "display Toast", toast.length_short).show(); The static method makeText of the Toast class is used to create a Toast object, using the show method to display the Toast on the interface. The first parameter corresponds to the context, the second parameter is the text to be displayed, and the third parameter is the time to be displayed. Constant is optional.Copy the code

Activity button listening

The onBackPressed() method can be overridden in an Activity to listen for the return key

@Override public void onBackPressed() { super.onBackPressed(); } If you want to listen for other keys, you can override the onKeyDown or onKeyUp methods to listen for pressed or pressed keysCopy the code

Share with you

I want to work my way up

Fly forward on the blades at the highest point

Let the wind blow dry tears and sweat

I want to work my way up

Waiting for the sun to watch its face

Little days have big dreams

I have my day

Let the wind blow dry tears and sweat

One day I will have my day