0

カメラタブには、カメラ、ギャラリー、リスト、履歴、ログアウトの5つのタブがあるタブアクティビティがあり、カメラを開いて写真を撮り、ギャラリーに保存すると同時に、この選択した画像でフォームを開きます。私の問題は、フォームに入力せずに他のタブに移動し、そのカメラに戻ると、 onActivityResult() 関数で使用されているのと同じレイアウトが表示されることです。ここに私のコードがあります。アクティビティ オープン 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();
            }



    });

}
4

0 に答える 0