0

I am programming a calendar. I created several activities:

  1. Mainactivity (default) in which there is a data picker and the following code: https://codeshare.io/aJxexR
  2. ora.activity where there is a timepicker
  3. activity_titolo where the user must input the title of the event
  4. finally I would like to create an activity that receives all the variables and creates a notification according to the date set by the user.

How do I pass all the data from the first activity to the last and create this notification?

project link https://drive.google.com/drive/folders/15Aom5n6CJwBV8l0H90MypmVTKlAr6FDe?usp=sharing

Conta
  • 236
  • 1
  • 6
  • 21

1 Answers1

1

have you considered using bundles to pass data in intents,here is what you have to do

  1. create a Parcelable class

  2. add it to bundle object and add the object to the intent that creates the final activity

  3. receive the bundles object from the new activity here is an example of a Parcelable class

    public class calender implements 
    Parcelable 
    {
    private String date;
    private String time;
    
    protected calender(Parcel in) {
    date = in.readString();
    time = in.readString();
    }
    
    public static final Creator<calender> 
    CREATOR 
    = new Creator<calender>() {
    @Override
    public calender createFromParcel(Parcel 
    in) {
        return new calender(in);
    }
    
    @Override
    public calender[] newArray(int size) {
        return new calender[size];
    }
    };
    
    public String getDate() {
    return date;
    }
    
    public void setDate(String date) {
    this.date = date;
    }
    
    public String getTime() {
      return time;
    }
    
    public void setTime(String time) {
    this.time = time;
    }
    
    @Override
    public int describeContents() {
    return 0;
    }
    
    @Override
    public void writeToParcel(Parcel dest, int 
    flags) {
    dest.writeString(date);
    dest.writeString(time);
    }
    }
    

and here is how you send the parceble class using intent

    Intent intent=new 
    Intent(CurrentActivty.this,
    finalActivty.class);
    calender calender=new calender();
    calender.setDate("example date");
    calender.setTime("example time");
    Bundle bundle=new Bundle();
    bundle.putParcelable("data",calender);
    intent.putExtra("calenderData",bundle);
    startActivity(intent);

and then finally you receive the intent data in your onCreate method

if (getIntent().getBundleExtra("calenderData")!=null)
    {
        calender calender =getIntent().getBundleExtra("calenderData").getParcelable("data");
       //do something with the calender variable
    }
    

here is documentation on class bundle