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