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,162
  • 4
  • 18
  • 31
Jawed Warsi
  • 139
  • 1
  • 2
  • 6

2 Answers2

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