title: How to use datepicker value in main activity?
body: <p>I want to use a datepicker in my app. I followed the steps from <a href="http://developer.android.com/guide/topics/ui/controls/pickers.html" rel="nofollow">http://developer.android.com/guide/topics/ui/controls/pickers.html</a> and developed the app. </p>
  
  <p>It has a method which is called when the date is picked.</p>
  
  <pre><code>public void onDateSet(DatePicker view, int year, int month, int day) {
  
      Toast.makeText(getContext(),"The date is: " + year + month + day ,Toast.LENGTH_LONG).show();
      // Do something with the date chosen by the user
  }
  </code></pre>
  
  <p>Now I want to use the date in main activity. The above method is in different class:</p>
  
  <pre><code>   package com.example.shiza.cube26;
  
  import android.app.DatePickerDialog;
  import android.app.Dialog;
  import android.os.Bundle;
  import android.support.v4.app.DialogFragment;
  import android.widget.DatePicker;
  import android.widget.Toast;
  
  import java.util.Calendar;
  
  /**
   * Created by Shiza on 04/10/2015.
   */
  public class DatePickerFragment extends DialogFragment
          implements DatePickerDialog.OnDateSetListener {
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          // Use the current date as the default date in the picker
          final Calendar c = Calendar.getInstance();
          int year = c.get(Calendar.YEAR);
          int month = c.get(Calendar.MONTH);
          int day = c.get(Calendar.DAY_OF_MONTH);
  
          // Create a new instance of DatePickerDialog and return it
          return new DatePickerDialog(getActivity(), this, year, month, day);
      }
  
      public void onDateSet(DatePicker view, int year, int month, int day) {
  
          Toast.makeText(getContext(),"The date is: " + year + month + day ,Toast.LENGTH_LONG).show();
          // Do something with the date chosen by the user
      }
  }
  </code></pre>
  
  <p>I want to get the value form onDateSet to the MainActivity. How can I do that? Please help me to solve this.</p>
  
  <p>Edit 1: </p>
  
  <p>I am using the sharedprefrences to solve the above issue:</p>
  
  <pre><code>protected void onResume() {
      super.onResume();
  
  
      final Calendar c = Calendar.getInstance();
      int year = c.get(Calendar.YEAR);
      int month = c.get(Calendar.MONTH);
      int day = c.get(Calendar.DAY_OF_MONTH);
  
      Toast.makeText(this,"I am in on resume",Toast.LENGTH_LONG).show();
  
  
      SharedPreferences sharedPreferences = this.getSharedPreferences("DATE_OF_JOURNEY", Context.MODE_PRIVATE);
  
      date = sharedPreferences.getString("DATE_OF_JOURNEY",null);
      if ( date  == null )
      {
          sharedPreferences.edit().putString("DATE_OF_JOURNEY", day + "/" + month + "/" + year).apply();
      }
  
      date_text.setText(date);
  
  
  }
  </code></pre>
  
  <p>I am writing date like this:</p>
  
  <pre><code>public void onDateSet(DatePicker view, int year, int month, int day) {
      sharedPreferences = getActivity().getSharedPreferences("DATE_OF_JOURNEY", Context.MODE_PRIVATE);
      Toast.makeText(getContext(),"The date is: " + year + month + day ,Toast.LENGTH_LONG).show();
  
      sharedPreferences.edit().putString("DATE_OF_JOURNEY", day + "/" + month+"/"+ year).apply();
      // Do something with the date chosen by the user
  }
  </code></pre>
  
  <p>But,still above code is not working?</p>