0

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();
            }



    });

}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Irshad Khan
  • 794
  • 6
  • 21
  • check if this helps you in anyway http://stackoverflow.com/questions/10777154/onactivityresult-is-not-working-in-tabactivitygroup or http://stackoverflow.com/questions/7812120/android-onactivityresult-never-called – G_S Nov 22 '12 at 16:00
  • thanks @sharath but my problem is the code inside onActivityResult thai is **setContentView(R.layout.publish);** called every time i want it called only when i choose picture from gallery or capture picture from camera please help – Irshad Khan Nov 23 '12 at 05:09
  • i didnt get your problem. Could you explain it in your question by editing it – G_S Nov 23 '12 at 05:27
  • @sharath Actually i want to use **setContentView(R.layout.publish);** only when i taken picture from camera or choose picture from gallery look in my code please. since it is use in starting of onActivityResult() function – Irshad Khan Nov 23 '12 at 07:40
  • why dont you start a new activity using intents – G_S Nov 23 '12 at 07:54

0 Answers0