Can i initialize object in my first activity and you it in all activity???
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));
}
}
How can i Initialize Calc object in MainActivity and use it PreviewActivity.
How can i pass it to another activity or how can i make it share with other activity
Use
Applicationclass by extending it and writing your customApplicationclass, and keep your objects in this class that you need in your crossActivitiesNow lets suppose in your A activity you create object of class
Objectand want to use it in your B Activity.do it this way,
You need to tell your
androidManifest.xmlabout your extendedApplicationclass.