[Android Development Learning] DAY07 & DAY08

Source: Internet
Author: User

content callback after interface jump or Content Callback

The previous interface delivers messages to the next interface

Let the jump intent carry parameters:

1. In the first interface: Intent package data

It.putextra ("msg"," bar -la-la-La ");

2. Remove data from the second interface

// Remove Data Method : guaranteed to get the same one from the previous interface it object.

Intent it=getintent ();

// Remove Data

String Msg=it.getstringextra ("msg");

// Assignment of Labels ———— String Data

Mtextview. SetText (msg);

Bring data back to previous page

1. Set the Start method change in the first interface:

Startactivityforresult (Intent, Requestcode);

Intent: Intentions

Requestcode: Request code, must be greater than 0

2. Set the method for returning results on the second page

Setresult (ResultCode, data)

ResultCode: Return code

Data: The intent to encapsulate the information.

3. Turn off the second interface

Finish ();

4. Overriding the Onactivityresult method in the first interface

// Determine the return code, if the request code matches, if the match, take out the data

if (requestcode==10&&resultcode==1) {

String Content=data.getstringextra ("second");

// bind data to component display

mgettx. SetText (content);

}

5. The second interface Intent intent gets cannot be completed at the member variable location.

Photo Callback

Choosepicture


Day 08

Multimedia audio and video recording

Mediarecorder

Mediarecorder Object

Each state is interpreted as follows:

Idle - Idle State

The Mediarecorder object is idle when a Mediarecorder object is created with the new statement or when its reset () method is called.

Calling the Reset () method in other states allows the Mediarecorder object to return to the idle state to achieve the purpose of re-using the Mediarecorder object.

Initialized - Initial State

After calling Setvideosource () or Setaudiosource (), Mediarecorder will enter the initialized state.

Whether to record audio or video depends on which method is called. For audio recording, the system supports recording data from a microphone or two audio sources on the phone.

Preparing - State of Readiness

After calling the Setoutputformat () method to specify the recording output format, Mediarecorder enters the preparing state.

In the preparing state, Mediarecorder also need to set the encoding format, file data path and other information.

Prepared-Ready State

When the prepare () method is called in the preparing state, the Mediarecorder object enters the prepared state, indicating that preparation is ready before recording.

recording - Recording Status

Call the Start () method, mediarecorder into the recording state, recording may take a while, Mediarecorder is always in the recording state.

Call the Stop () method, Mediarecorder stops recording, prints the recording to the specified file, and then returns to the idle state.

released - Release Status

Mediarecorder consumes audio and video hardware resources, so you should call the release () method to destroy the Mediarecorder object when it is no longer needed to free up resources.

Error - Error Status

If, for some reason, an error occurs, Mediarecorder enters the error state and triggers an event that invokes the Onerrorlistener OnError () method (if provided).

Mediarecorder also defines a oninfolistener nested interface to listen for error messages during recording.

For example, if the recording length reaches the maximum limit or the recording file size reaches the maximum file limit, the system will callback the Oninfo () method of the registered Oninfolistener interface.

Compared with MediaPlayer, the Mediarecorder is relatively simple. The state of the object should be reasonably controlled in order to ensure the correct operation of the recording program.

Framework code for audio recording programs

Initializing the Mediarecorder object

1. Mediarecorder Recorder = new Mediarecorder ();

Set Audio source

2. Recorder.setaudiosource (MediaRecorder.AudioSource.MIC);

Setting the audio output format

3. Recorder.setoutputformat (MediaRecorder.OutputFormat.THREE_GPP);

Set the audio encoding format

4. Recorder.setaudioencoder (MediaRecorder.AudioEncoder.AMR_NB);

Set output file path: Save to SDcard

5. Recorder.setoutputfile (path_name);

Get ready

6. Recorder.prepare ();

Start recording

7. Recorder.start ();

Recording ...

8. Recorder.stop ();

Stop it

9. Recorder.reset ();

Reset

10.recorder.release ();

Freeing resources

[Android Development Learning] DAY07 & DAY08

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.