Another way to communicate between Android components

Source: Internet
Author: User
Tags call back

Creatependingresult (intint flags)  

Parameter description

int Requestcode request code, equivalent to Startactivityforresult's request code

Intent data default result, equivalent to Setresult data

int flags flag bit, not quite understand, the decrepit passed a 0

The function of this activity is to get a pendingintent, anywhere, to callback the onactivityresult of the activity that created the intent.

Passed as a pendingintent to other components, and then the other components are called to finish, get pendingintent,

Calling the overloaded method of send and send, the Onactivityresult method of the activity is returned to return the processing result.

Wrote a demo.

parameter Description int Requestcode request code, equivalent to Startactivityforresult's request code intent Data default result, equivalent to Setresult data int flags, not quite. 0 The way the activity works is to get a pendingintent, anywhere, to call back the onactivityresult of the activity that created the intent. As a pendingintent is passed to other components, and then other component calls are completed, get pendingintent, call the overloaded method of send and send, and back-tune the activity's Onactivityresult method to return processing results. Wrote a demo.

The activity created a pendingintent in the OnCreate, and put it in intent, then opened the

Myserivice, prints the value passed by MyService in the Onactivityresult method

The activity creates a pendingintent in the OnCreate, and puts it in intent, then opens the Myserivice and prints the Onactivityresult pass value in the MyService method.

In the service OnStart method, the delay of 3 seconds to perform a task, this task is to get the Mainactivity pass over the pendingintent,

Then send it together with a resultcode and data (if the Creatependingresult set the data, send here will not be modified),

The Mainactivity Onactivityresult method is called back and the result is printed as follows

E/xxxxx (1827): MyService onStart   E/xxxxx (1827101, data = Service return Data  

This method can be used to interact with the service, or to pass data across activity, such as a, B, c three activity,a open b,b open C,

Then B automatically shuts down, a receives the result of C, you can use this way to pass the Pendingintent implementation, more application scenarios by you to find.

Another way to communicate between Android components

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.