答案 0 :(得分:0)
Intent activityTwo = new Intent(this, Activity2.class);
activityTwo.putIntExtra("key", sumSettlement);
startActivity(activityTwo);
现在,在Activity2
:
if(getIntent() != null) {
textView.setText(String.valueOf(getIntent.getExtra("key"));
}
答案 1 :(得分:0)
您可以使用本地广播接收器。
活动B中的第一个注册接收器
//in onCreate Method
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
new IntentFilter("my-event-name"));
// It will be called whenever an Intent
// with an action named "my-event-name" is broadcasted.
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Get extra data included in the Intent
String message = intent.getStringExtra("message");
// show this message in textview
}
};
在活动A中
//broadcast this
Intent intent = new Intent("my-event-name");
intent.putExtra("message", Integer(sumSettlment).toString());
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
答案 2 :(得分:0)
最简单的方法是使用Intent:在第一个Activity中
Intent intent =new Intent(CurrentClass.this,DisClass.class);
intent.putExtra("myTextValue",textView.getText().toString());
startActivity(intent);
dist活动中的执行以下操作:
String myValue=getIntent().getExtra().getString("myTextValue");
textView.setText(myValue);