在另一个 activity 中显示得分结果

Displaying score result in another activity

我怎样才能在另一个 activity 的 activity 中显示得分结果?我在这里有我的 MainActivity 和 ScoreActivity。我想通过 MainActivity 的 TextView 在 ScoreActivity 中显示分数。是否可以?我怎样才能做到这一点?

MainActivity

//COUNTDOOWNTIMER
public void onFinish() {
   // TODO Auto-generated method stub
   timer.setText("Time's Up!");
   topScore.setText(score.getText());//the textview for best score
   run();//to store the value in topScore
   
   Intent i = new Intent("app.thesis.boggleit.TOPSCORE");
   startActivity(i); //themedActivity
   
   Intent score = new Intent(MainActivity.this, TopScore.class);
   score.putExtra("scores", topScore.getText().toString());
   
   }

TopScore

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TopScore extends Activity{

 TextView topscore;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.top_score);
  
  topscore = (TextView) findViewById(R.id.tvNewTScore);
  
  String scores = getIntent().getStringExtra("scores");
  topscore.setText(scores);
  
 }

}

主要activity:

public void onFinish() {
        // TODO Auto-generated method stub
        timer.setText("Time's Up!");
        topScore.setText(score.getText());//the textview for best score
        run();//to store the value in topScore

        Intent i = new Intent(MainActivity.this,ScoreActivity.class);
        i.putExtra("scores", topScore.getText().toString());

        startActivity(i); //themedActivity
}

得分:

String scores = getIntent().getStringExtra("scores");

在您的意向消息对象中,添加一个包并保存您的分值。

在分数 Activity 中,从包中检索值。

主要Activity :

Intent intent = new Intent();
intent.setClass(this, Score_Activity.class);
intent.putExtra("EXTRA_ID", "Score Value");
startActivity(intent);

在Score_Activity中:

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  Bundle extras = getIntent().getExtras();
  if (extras != null) {
   String datas= extras.getString("EXTRA_ID");
   if (datas!= null) {
        // do stuff
   }        
}