How to Pass Current Date from One activity to next activity(Pass the current date to the soap services) in android only using click event and intent.....
Asked
Active
Viewed 2,867 times
0
-
try this link http://stackoverflow.com/questions/5382081/android-passing-date-in-putexra – likith sai Mar 27 '15 at 12:22
2 Answers
1
From the current activity:
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("date", dateObj.getTime());
startActivity(intent);
From next activity:
Date dateObj = new Date(getIntent().getExtras().getLongExtra("date", -1));
You should pass the time as a long value and convert it back on the other activity to avoid date parsing from string issues on different devices.

DirtyBit
- 16,613
- 4
- 34
- 55

Alka Jadav
- 115
- 2
- 13
1
public String getCurrentDate() {
Time time = new Time();
time.setToNow();
time.month = time.month + 1;
String date = String.valueOf(time.year) + "-"
+ String.valueOf(time.month) + "-"
+ String.valueOf(time.monthDay);
return date;
}
in your onClick Listener Add This Code
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("date", getCurrentDate());
startActivity(intent);
In Your Next Activity's onCreate() Add This Code.
String date=getIntent().getStringExtra("date");
You can parse this date into Date object

Satheesh Kumar
- 197
- 2
- 14