我可以在我的第一个活动中初始化对象,而你可以在所有活动中初始化它吗???
public class Calc{
int x;
int y;
public Calc(int x, int y) {
this.x = x;
this.y = y;
}
public int sum() {
return x + y;
}
}
public class MainActivity extends Activity {
private int progressStatus = 0;
private Handler handler = new Handler();
private ProgressBar loading;
private static int progress;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Calc c = new Calc(3, 4);
}
}
public class PreviewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preview);
TextView txt = (TextView) findViewById(R.id.txt);
txt.setText(Integer.toString(c.sum));
}
}
我如何在 MainActivity 中初始化 Calc 对象并使用它 PreviewActivity。
我如何将其传递给另一个活动或如何使其与其他活动共享