【发布时间】:2016-08-09 13:29:46
【问题描述】:
【问题讨论】:
【问题讨论】:
最简单的方法是使用 Intent: in first 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);
【讨论】:
您可以使用本地广播接收器。
Activity 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);
【讨论】:
Intent activityTwo = new Intent(this, Activity2.class);
activityTwo.putIntExtra("key", sumSettlement);
startActivity(activityTwo);
现在,Activity2:
if(getIntent() != null) {
textView.setText(String.valueOf(getIntent.getExtra("key"));
}
【讨论】: