Hi
I have started camera using startActivityForResult() from my PhotosFragment
and decode the image and display on grid view on fragment using adapter. It
captures image and onActvityResult called properly and all code on
onActvityResult works fine(find through debug).But I need to display the
camera taken image on gridview on fragment.After taking picture and save,it
goes to Photofragment onActivityResult,and then go to home fragment
directly(I have loaded HomeFragment and PhotosFragment on MainActivity).Not
displayed It ocurs only on Samsung S4 device only.
I have tried by changing config parameter of Activity in manifest.But not
works for me.
*Reference:*
Android: Activity getting Destroyed after calling Camera Intent
http://stackoverflow.com/questions/16014930/android-activity-getting-destroyed-after-calling-camera-intent
http://stackoverflow.com/a/10411504
*PhotosFragment.java*
private void selectImage() {
final CharSequence[] items = {Take Photo, Choose from Library,
Cancel};
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(Add Photo);
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals(Take Photo)) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment
.getExternalStorageDirectory(), temp.jpg);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, REQUEST_CAMERA);
} else if (items[item].equals(Choose from Library)) {
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType(image/*);
startActivityForResult(
Intent.createChooser(intent, Select File),
SELECT_FILE);
} else if (items[item].equals(Cancel)) {
dialog.dismiss();
}
}
});
builder.show();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode,resultCode,data);
Log.i(CameraResult,requestCode-+requestCode+where
REQUEST_CAMERA-+REQUEST_CAMERA);
Log.i(CameraResult,resultCode-+resultCode+where
getActivity().RESULT_OK-+getActivity().RESULT_OK);
Log.i(CameraResult,data-+data);
if (resultCode == getActivity().RESULT_OK) {
int thumbFactor = 6; // choose a power of 2
if (requestCode == REQUEST_CAMERA) {
File f = new File(Environment.getExternalStorageDirectory()
.toString());
for (File temp : f.listFiles()) {
if (temp.getName().equals(temp.jpg)) {
f = temp;
break;
}
}
Log.i(CameraResult,f.getAbsolutePath()-+f.getAbsolutePath());
try {
imagePaths.add(f.getAbsolutePath());
//CarPicturesAdapter adapter = new
CarPicturesAdapter(getActivity().getBaseContext(), R.id.pictureGrid,
images);
CarPicturesAdapter adapter = new
CarPicturesAdapter(getActivity().getBaseContext(), R.id.pictureGrid,
imagePaths);
contentImage.setAdapter(adapter);
Log.i(CameraResult, set adapter);
f.delete();
Log.i(CameraResult, file deleted);
} catch (Exception e) {
e.printStackTrace();
}
//super.onActivityResult(requestCode,resultCode,data);
}
/*else{
super.onActivityResult(requestCode,resultCode,data);
}*/
}
}
*CarPicturesAdapter.java*
public class CarPicturesAdapter extends ArrayAdapterString{
private SparseBooleanArray mSelectedItemsIds;
private final ArrayListString objects;
private Context context;
private String[] images;
public CarPicturesAdapter(Context context, int textViewResourceId,
ArrayListString objects) {
super(context, textViewResourceId, objects);
this.context = context;
this.images = new String[objects.size()];
objects.toArray(this.images);
this.objects = objects;
mSelectedItemsIds = new SparseBooleanArray();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);