how to move back to a particular activity after Image capturing in android
in my app i have two activities namely A and B. From activity A i am moving to activity B by clicking a button. In activity B i have a button and when the use clicks it opens either the library or camera according to the user's wish.
Here either the user selects an image or captures an image, the image is been uploaded to server. After this activity gets overed i want to show the Activity A automatically.
If the user clicks the default back button, i have written cod开发者_高级运维e to move to Activity A, butin some times it gets closed automatically after the uploading process, in such case i want to show only Activity A and not B.
Use this for Taking Photo and store it in Sdcard :
public void takePhoto() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File folder = new File(Environment.getExternalStorageDirectory() + "/Photo");
boolean success = false;
if(!folder.exists()){
success = folder.mkdir();
}
final Calendar c = Calendar.getInstance();
String path=String.format("/sdcard/Photo/%s.png","Photos");
photo = new File(path);
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
startActivityForResult(intent, TAKE_PICTURE);
}
Use onActivityResult Method :
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case TAKE_PICTURE:
if (resultCode == Activity.RESULT_OK) {
// Use your server Post Coding :
// Get the Rsponse as String and compare here
if(response.equalsignoreCase("POST SUCCESS")){
startActivity(new Activity (CurrentActivity.this,Activity2.class))
}
super.onActivityResult(requestCode, resultCode, data);
}
}
After the Image captured from Camera its will come to onActivityResult() method Check the Response and Redirect the Page Accordingly.
Call finish();
when you're done with Activity B and it will reliably close and return to Activity A.
精彩评论