In my application I need a variable from one activity to another activity without using any intent. So I have declared that variable as static and used as FirstActivit
Try to initialize firstly your class. But what I see you want to have some application context that is accessible via application. For that porpouse you can simply use that method but data try to keep in SharedPreferences. So simply when you get sth from ApplicationClass you simply get it firstly from shared preferences and return. :) And each time when you need your ApplicationClass you initialize it and there methods run shared preferences to get data.
public class Detail extends Activity{
ApplicationClass ac = new ApplicationClass();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stockdetail);
ac=new ApplicationClass();
ac.setStockName(getIntent().getExtras().getString("StockName"));
}
Shared preferences context class.
public ApplicationClassWithSharedPreferences{
private Context context;
public ApplicationClassWithSharedPreferences(Context c){
context = c;
}
public String getSomeValueFromContext(){
SharedPreferences sharedPref = context.getPreferences(Context.MODE_PRIVATE);
String highScore = sharedPref.getString("KEY", "DEFAULT");
return highScore;
}
}