我可以在第一个活动中初始化对象,而在所有活动中都可以初始化对象吗?
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.
如何将其传递给其他活动,或如何使其与其他活动共享