Centralized knowledge about Android, Android
Because android has many knowledge points, it is easy to mix and forget things, so it is concentrated here for a long time.
I,Use of AlarmManager
1. AlarmManager, as its name implies, is a "Reminder". It is a commonly used system-level prompt service in Android and broadcasts a specified Intent to us at a specific time. In short, we set a time, and then when the time comes, AlarmManager broadcasts a set Intent for us. Generally, we use PendingIntent, which can be understood as an Intent package, simply put, a specified action is added to the Intent. When using Intent, we also need to execute startActivity, startService or sendBroadcast to make Intent useful. PendingIntent includes this action.
Defines a PendingIntent object.
PendingIntent pi = PendingIntent. getBroadcast (this, 0, intent, 0 );
2. There are three common AlarmManager methods:
(1) set (int type, long startTime, PendingIntent pi );
This method is used to set a one-time alarm. The first parameter indicates the alarm type, the second parameter indicates the alarm execution time, and the third parameter indicates the alarm response action.
(2) setRepeating (int type, long startTime, long intervalTime, PendingIntent pi );
This method is used to set a repeated alarm. The first parameter indicates the alarm type, the second parameter indicates the first execution time of the alarm, and the third parameter indicates the interval between two executions of the alarm, the third parameter indicates the alarm response action.
(3) setInexactRepeating (int type, long startTime, long intervalTime, PendingIntent pi );
This method is also used to set repeated alarms, similar to the second method, but the interval between the two alarms is not fixed.
3. The parameters of the three methods are described in detail:
(1) int type: Specifies the alert clock type. Five values are commonly used: AlarmManager. ELAPSED_REALTIME, AlarmManager. Timeout, AlarmManager. RTC, AlarmManager. RTC_WAKEUP, and AlarmManager. POWER_OFF_WAKEUP.
AlarmManager. ELAPSED_REALTIME indicates that the alarm is unavailable when the mobile phone is sleeping. In this status, the relative time (relative to the start time of the system) is used for the alarm, and the status value is 3;
AlarmManager. ELAPSED_REALTIME_WAKEUP indicates that the alarm will wake up the system during sleep and execute the prompt function. In this status, the alarm will also use relative time, And the status value is 2;
AlarmManager. RTC indicates that the alarm is unavailable during sleep. In this status, the absolute time is used for the alarm, that is, the current system time. The status value is 1;
AlarmManager. RTC_WAKEUP indicates that the alarm will wake up the system during sleep and execute the prompt function. In this status, the alarm uses the absolute time and the status value is 0;
AlarmManager. POWER_OFF_WAKEUP indicates that the alarm notification function can be performed normally when the phone is shut down. Therefore, it is one of the five most frequently used states. In this status, the alarm notification uses absolute time and the status value is 4; however, this status seems to be affected by the SDK version, which is not supported by some versions;
(2) long startTime: the first execution time of the alarm, in milliseconds. The time can be customized, but the current time is generally used. Note that this attribute is closely related to the first attribute (type). If the first parameter uses the relative time (ELAPSED_REALTIME and ELAPSED_REALTIME_WAKEUP) for the alarm ), this attribute uses the relative time (relative to the system startup time). For example, the current time is represented as SystemClock. elapsedRealtime (); if the alarm clock corresponding to the first parameter uses absolute time (RTC, RTC_WAKEUP, POWER_OFF_WAKEUP), this attribute uses absolute time. For example, the current time is expressed: system. currentTimeMillis ().
(3) long intervalTime: For the last two methods, this attribute exists, indicating the interval between the two alarms, in milliseconds.
(4) PendingIntent pi: it is bound to the execution action of the alarm, such as sending a broadcast and giving a prompt. PendingIntent is the encapsulation class of Intent. It should be noted that if the alarm is triggered by starting the service, the PendingIntent object should be obtained using Pending. getService (Context c, int I, Intent intent, int j) method; if the alarm is triggered through broadcast, the PendingIntent object should be obtained using PendingIntent. getBroadcast (Context c, int I, Intent intent, int j) method; if the alarm is triggered by an Activity, the PendingIntent object should be obtained by PendingIntent. getActivity (Context c, int I, Intent intent, int j) method. If these three methods are used incorrectly, although no error is reported, the alarm is not displayed.
4. Example: Define an alarm and repeat the response in 5 seconds.
(1) MainActivity, completed in onCreate:
[Java]View plaincopy?
- // Create an Intent object. The action is ELITOR_CLOCK, and the additional information is the string "you should make soy sauce"
- Intent intent = new Intent ("ELITOR_CLOCK ");
- Intent. putExtra ("msg", "You should have soy sauce ");
- // Define a PendingIntent object. PendingIntent. getBroadcast contains the sendBroadcast action.
- // That is, intent with the action "ELITOR_CLOCK" is sent.
- PendingIntent pi = PendingIntent. getBroadcast (this, 0, intent, 0 );
- // AlarmManager object. Note that this is not a new object. Alarmmanager is a system-level service.
- AlarmManager am = (AlarmManager) getSystemService (ALARM_SERVICE );
- // Set the PendingIntent object pi every 5s from the current time. Pay attention to the relationship between the first parameter and the second parameter.
- // Send broadcast in 5 seconds through the PendingIntent pi object
- Am. setRepeating (AlarmManager. RTC_WAKEUP, System. currentTimeMillis (), 5*1000, pi );
After MainActivity is started, AlarmManager am is defined and am is called. setRepeating (...) function, the system starts intent to send broadcasts every 5s, and its action is ELITOR_CLOCK. Therefore, we need to register a receiver in Manifest. xml and define a broadcast receiver class at the same time.
(2) define a broadcast receiver class MyReceiver and override the onReceive () function.
[Java]View plaincopy?
- Public class MyReceiver extends BroadcastReceiver
- {
- @ Override
- Public void onReceive (Context context, Intent intent)
- {
- // TODO Auto-generated method stub
- Log. d ("MyTag", "onclock ......................");
- String msg = intent. getStringExtra ("msg ");
- Toast. makeText (context, msg, Toast. LENGTH_SHORT). show ();
- }
- }
(3) register a broadcast receiver in Manifest. xml:
[Html]View plaincopy?
- <Cycler android: name = ". mycycler">
- <Intent-filter>
- <Action android: name = "ELITOR_CLOCK"/>
- </Intent-filter>
- </Cycler>
The android learning method has been learned in the past, and some simple layout controls have been connected, but I do not know how to learn it. I want to watch videos.
I think I should join more Android forums and ask more experts on the forums. They all have the secret. Even the students have the correct learning method.
More than two thousand years ago, Confucius said: "A person who knows is better than a person who knows better than a person who is happy ." It means to do one thing, to know it, to know it is better to love it, to love it is better to enjoy it. "Good" and "happy" means you are willing to learn and enjoy learning. This is your interest. Interest is the best teacher. If you are interested, you can have a hobby. If you are interested, you must practice it and enjoy it. If you are interested, you will have the initiative and enthusiasm for learning. So: interest is an inexhaustible source of motivation for learning. As long as you prepare for the course on weekdays to find out difficult questions, actively participate in classroom activities, carefully think about problems, and actively speak to collect incentive factors, then you will be more interested in learning, and you will be more interested in learning cultural courses.
To achieve good academic performance, you must have good study habits. The habit is the steady and persistent conditioned reflection and natural needs consolidated after repeated exercises. Establishing good study habits will make your learning feel orderly and easy. Good study habits should be: ears, eyes, brain, Mouth, hands-on, diligent exercises, multi-questioning, Diligent Thinking, re-induction, and multi-application. Pay attention to summing up regular things, in the course of learning, we need to translate the knowledge that teachers teach into our own special language and remember it permanently in our own minds. In addition, make sure that you have a certain amount of self-study time every day to broaden your knowledge and cultivate your learning ability.
1. preview the course. Pre-course preparation is an important strategy to improve the effect of lectures. Pre-course preparation is to preview the content to be taught in this course before each class. You are familiar with the course content, find the key points, difficulties, and doubts of the lectures and understanding, and write down your own puzzles and weaknesses, take the problem into the classroom, in order to solve the problem in the classroom learning.
2. classroom learning. Follow the teacher's ideas as much as possible in the classroom, and try to keep yourself in a positive listening state. Think carefully about the key points, difficulties, and doubts of the teacher, through lectures, we can solve the problems raised during previewing, deepen our understanding of the problems, and train our own thinking through lectures. Do not be satisfied with the teacher's ideas. think more about other methods or possibilities. Classroom learning is a process of two-way communication: on the one hand, the teacher tells you, and on the other hand, by giving your feedback to the teacher, the teacher knows whether the content he is talking about is understood by you. Therefore, you must think positively, answer the questions raised by the teacher, and express your opinions and opinions so that the teacher can understand your current thinking level. Take note of the lecture carefully, write down the key points, key points, and difficulties of the text, explain, prompt, and opinions of the teacher, and explain and understand your own questions. As the saying goes, "a good memory is worse than a bad pen." A sensitive head cannot resist time consumption. Note taking is a good supplementary learning method. It helps you overcome the limitations of your brain's memory and reminds you to recall the content of your classroom. However, taking notes cannot be a mechanical copy of the instructor's content. It is also a process of thinking. Make a proper choice when taking notes. The details are slightly moderate. The focus is on the key points prompted by the teacher and the difficulties you don't know. The process of taking notes must be scientifically distributed and focused on the difficulty of the subjects: For difficult subjects, 50% of the time can be heard, and 50% of the time can be taken; for subjects that focus more on flexibility and creativity, 90% of the time is enough to listen, and 10% of the time is enough to write down the outline. Note must be well-organized and clear at a glance to make notes more valuable.
3. Review after class. Review the course content in a timely manner, actively recall and re-learn as necessary to deepen the overall understanding of the course content and reduce forgetting. In addition, the process of forgetting is unbalanced. At the beginning, the process of forgetting is much faster and less forgotten in the future. According to the Law of forgetting, you can adopt appropriate review strategies to overcome forgetting. That is, you can avoid forgetting Before forgetting. Therefore, pay attention to the time schedule during the review.
According to the relevant research, the effective review schedule is:
5-10 minutes after the first review.
The second review, later or the next day.
The third review, about a week.
The fourth review, about a month.
The Fifth Review, about half a year.
Review based on the above method to effectively combat forgetting. "Live to the old, learn to be old ." People can't do without learning, life is endless, and learning is not limited. Learning refers to the process in which a person gains knowledge, experiences, and behaviors for life.
What knowledge does Android development need?
Java's various data structures and syntaxes must be well mastered.
Then we can start Android. It is not difficult to learn Android.
Remember to read more official documents, find two forums, and create two projects to get started.