1.Intent intent = new Intent(this, MainMenu.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
上述情况是指 如果你有多个activivty,如果俺back建要一丛丛返回,上面的实现了只返回到主界面
2.
private static final int MEDIA_IMAGE_REQUEST_CODE = 203948; // This can be any unique number you like
Intent getImageFromGalleryIntent =
new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(getImageFromGalleryIntent, MEDIA_IMAGE_REQUEST_CODE);
protected final void onActivityResult(final int requestCode, final int resultCode, final Intent i) {
super.onActivityResult(requestCode, resultCode, i);
if(resultCode == RESULT_OK) {
switch(requestCode) {
case MEDIA_IMAGE_REQUEST_CODE:
// Get the chosen images Uri
Uri imageUri = i.getData();
// Load the bitmap data from the Uri
// It is probably best to do this in an AsyncTask to avoid clogging up the Main Thread
break;
}
}
本文介绍了Android中Intent的两种典型使用场景:一是通过设置FLAG_ACTIVITY_CLEAR_TOP标志位实现按下返回键直接回到应用主界面;二是从图库选择图片并获取所选图片的URI。

被折叠的 条评论
为什么被折叠?



