Android活动数据介于2个活动之间

时间:2014-05-14 22:10:04

标签: android android-intent android-activity

我有一个问题,我正在开发一个带有允许您签名的活动的应用。但是当我点击“保存”时,尽管我使用了finish(),但活动仍未关闭。

活动B:

public class Signature extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signature);

    Button Enregistrement = (Button)findViewById(R.id.DoneButton);
    Enregistrement.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v)
        {
            try {
                GestureOverlayView gestureView = (GestureOverlayView) findViewById(R.id.pad);
                gestureView.setDrawingCacheEnabled(true);
                Bitmap result = Bitmap.createBitmap(gestureView.getDrawingCache());
                Intent returnIntent = new Intent();
                returnIntent.putExtra("result",result);
                setResult(RESULT_OK,returnIntent);
                finish();

           } catch (Exception e) {
               Log.v("Gestures", e.getMessage());
               e.printStackTrace();
           }
        }
    });
}

}

活动A:

public class InfoAdherent extends Activity {

private Bitmap imgSign;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_info_adherent);
    // Check Box Nouvel Adherent EPC Listener.
    CheckBox cbNouvelAdAPC = (CheckBox) findViewById(R.id.cbNouvelAdherentAPC);
    cbNouvelAdAPC.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
                if (((CheckBox) v).isChecked())
                {
                     TextView textMontant = (TextView) findViewById(R.id.textTarif);
                     textMontant.setText("Le tarif de l'adhésion est de : 25 Euros.");
                }
                else 
               {
                    TextView textMontant = (TextView) findViewById(R.id.textTarif);
                    textMontant.setText("Le tarif de l'adhésion est de : 20 Euros.");
               }
          }
        });
    // Fin CheckBox nouvel Adherent EPC
    // Boutton signature
    Button getSignature = (Button) findViewById(R.id.buttonSignature);
    getSignature.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent intent = new Intent(getApplicationContext(), Signature.class); 
            startActivityForResult(intent,1);
        }
    });
    //Fin Boutton signature
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == 1) {
        if(resultCode == RESULT_OK){
            Bitmap result=(Bitmap) data.getParcelableExtra("result");
            this.imgSign = result;
            Context context = getApplicationContext();
            CharSequence text = "Message Recu";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();

        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }
    }
}//onActivityResult

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.info_adherent, menu);
    return true;
}

}

感谢您的帮助:)

0 个答案:

没有答案