I have Tab Activity with 5 tab namely camera,gallery,listing ,history and logout in camera tab I open camera and take picture and save in gallery and at the same time I open form with this picked image. My problem is when I don't fill form and move to other tab and the again back to that camera it show same layout used in onActivityResult() function here is my code. please give me answer that can we finish activity open onActivityResult().
public class PhotoScreen extends Activity{
//private static final String[] COUNTRIES = new String[] {"Apartment", "Land"};
public int TAKE_PICTURE = 0;
Button takepicture;
public static String propertynamevalue;
Bitmap mBitmap = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photolayout);
takepicture = (Button) findViewById(R.id.button1);
takepicture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data)
{
setContentView(R.layout.publish);
super.onActivityResult(requestCode, resultCode, data);
final DatabaseHandler db=new DatabaseHandler(this.getBaseContext());
Button save =(Button)findViewById(R.id.save);
if (requestCode == TAKE_PICTURE)
{
if(resultCode == RESULT_OK)
{
Log.v("test", "Camera intent succeeded");
mBitmap = (Bitmap) data.getExtras().get("data");
ImageView imageView =(ImageView)findViewById(R.id.imgView);
Canvas can = new Canvas();
can.setBitmap(Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.RGB_565));
imageView.setImageBitmap(mBitmap);
}
else if(resultCode == RESULT_CANCELED)
{
setContentView(R.layout.photolayout);
Log.i("test1", "Camera intent aborted");
}
else
{
Log.e("test2", "Camera intent failed with result code: " + resultCode);
}
}
save.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// Inserting Property
EditText propname=(EditText)findViewById(R.id.etcity1);
EditText propcost=(EditText)findViewById(R.id.etcity2);
EditText propaddress=(EditText)findViewById(R.id.etcity3);
EditText propbuilduparea=(EditText)findViewById(R.id.etcity4);
EditText propcategory=(EditText)findViewById(R.id.etcity5);
Log.d("Insert: ", "Inserting ..");
db.addProperty(new Property(propname.getText().toString(), propcost.getText().toString(),propaddress.getText().toString(),propbuilduparea.getText().toString(),propcategory.getText().toString()));
//Log.d("propcost: ", ""+Double.parseDouble(propcost.getText().toString())+"");
propname.setText("");
propcost.setText("");
propaddress.setText("");
propbuilduparea.setText("");
propcategory.setText("");
// Reading all contacts
List<Property> property = db.getAllContacts();
for (Property cn : property){
Log.d("Reading: ", "Reading all contacts..");
String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Cost: " + cn.getCost()+ " ,Address: " + cn.getAddress()+ " ,Builduparea: " + cn.getBuilduparea()+" ,Category: " + cn.getCategory();
// Writing Contacts to log
Log.d("Name: ", log);
}
setContentView(R.layout.photolayout);
Toast.makeText(getApplicationContext(), "Your Data Has been saved successfully", Toast.LENGTH_LONG).show();
}
});
}