两个活动之间的Android活动数据
我有一个问题,我正在开发一个应用程序,其中包含一个允许您签名的活动。但是,当我单击“保存”时,尽管我使用finish(),活动仍不会关闭 活动B:两个活动之间的Android活动数据,android,android-intent,android-activity,Android,Android Intent,Android Activity,我有一个问题,我正在开发一个应用程序,其中包含一个允许您签名的活动。但是,当我单击“保存”时,尽管我使用finish(),活动仍不会关闭 活动B: public class Signature extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac
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;
}
}
谢谢您的帮助:)我知道这可能太明显了,您已经注意到了,但只想检查一下。您的“保存”id是否定义为R.id.DoneButton?为什么不在点击监听器中显示一条Toast消息,以确保您跟踪的是正确的点击。为什么在完成之前您没有启动活动?我认为您不需要启动活动,因为他只想返回启动它的活动。最后,我了解到,我们必须在所有活动的请求代码中指定RESULT__OK。。。