0

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.....

Ratilal Chopda
  • 4,113
  • 4
  • 17
  • 29
Jawed Warsi
  • 129
  • 1
  • 2
  • 5

2 Answers2

2
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,151
  • 4
  • 28
  • 54
Alka Jadav
  • 401
  • 2
  • 14
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
  • 187
  • 2
  • 14