Using Android's intent to invoke another activity, the use of a multithreaded mechanism, asynchronous way. Startactivityforresult is called after the activity does not return the result immediately to the Acitivity object that called Activity,android The Startactivityforresult source code has the relevant explanation.
/**
* Launch an activity for which you would like a result? ? ? ? ? ? When it finished. ? ? ? ? ? ?
* When this activity exits, your
* Onactivityresult () method is called with the given Requestcode.
* Using A negative requestcode is the same as calling
* {@link #startActivity} (the activity is not launched as a sub-activity).
*
* <p>note that this method should is used with Intent protocols
* That is defined to return a result. In other protocols (such as
* {@link Intent#action_main} or {@link Intent#action_view}), May
* Not get the result when you expect. For example, if the activity you
* is launching uses the Singletask launch mode, it won't run in your
* Task and thus you'll immediately receive a cancel result.
*
* <p>as A special case, if your call Startactivityforresult () with a requestcode
* >= 0 during the initial onCreate (Bundle savedinstancestate)/onresume () of your
* Activity, then your window'll not being displayed until a result is
* Returned back from the started activity. This was to avoid visible
* Flickering when redirecting to another activity.
*
* <p>this method throws {@link Android.content.ActivityNotFoundException}
* If there is no Activity found to run the given Intent.
*
* @param intent the intent to start.
* @param requestcode If >= 0, this code would be returned in
* Onactivityresult () when the activity exits.
* @param options Additional options for how the Activity should is started.
* See {@link android.content.context#startactivity (Intent, Bundle)
* Context.startactivity (Intent, Bundle)} for more details.
*
* @throws android.content.ActivityNotFoundException
*
* @see #startActivity
*/
public void Startactivityforresult (Intent Intent, int requestcode, @Nullable Bundle options)
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
Button Pbutton = (button) Findviewbyid (R.id.btn_return);
Pbutton.setonclicklistener (New Onclicklistener () {
public void OnClick (View v) {
//TODO auto-generated method stub
Intent pintent = new Intent (mediastore.action_image_capture);//Call camera ACTION
Startactivityforresult (pintent,intent_code_image_capture);//requestcode
Startactivityforresult If you get the intent object right away many of the members are NULL
}
});
protected void onactivityresult (int requestcode, int resultcode, Intent data) {
//TODO auto-generated method stub
Super.onactivityresult (Requestcode, ResultCode, data);
if (requestcode==intent_code_image_capture && data! = NULL) {
final ImageView Pimageview = (ImageView) Findviewbyid (R.ID.IMAGEVIEW1);
Bundle pbundle = Data.getextras (); Gets the data from the intent object,
if (pbundle! = null) {
Bitmap pbitmap = (Bitmap) pbundle.get ("Data");
if (Pbitmap!=null) {
Pimageview.setimagebitmap (PBITMAP);
pimageview.refreshdrawablestate ();
log.i ("Result", "Capture picture succeed");
}
Else {
log.i ("Result", "Capture picture failure");
}
}
}
Else if (Requestcode = = 0) {
Toast.maketext (This, "TE", Toast.length_long). Show ();
log.i ("Other", "result");
}
}
The intent mechanism for Android is available for reference:
http://www.oschina.net/question/565065_67909
The essentials of Android Development has a very comprehensive introduction
Android uses intent to call the camera and get photos