0

I need to get the variable date from the class SetAlarmActivity to the MainActivity

SetAlarmActivity

     }
    });
    tvSTART.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar mcurrentTime = Calendar.getInstance();
            int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
            int minute = mcurrentTime.get(Calendar.MINUTE);
            TimePickerDialog mTimePicker;
            mTimePicker = new TimePickerDialog(SetAlarmActivity.this, new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    tvSTART.setText( selectedHour + ":" + selectedMinute);
                    tv_START = ( selectedHour + ":" + selectedMinute);
                    DateFormat format = new SimpleDateFormat("h:mm", Locale.ENGLISH);
                    try {
                       Date date = format.parse(tv_START);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
            }, hour, minute, true);//Yes 24 hour time
            mTimePicker.setTitle("Select Start Time");
            mTimePicker.show();

        }
    });
Lior Dahan
  • 29
  • 3
  • Put it in `sharedpreferences`? – SQLiteNoob Sep 05 '17 at 20:41
  • how you go from this activity to main activity ?? – Aalap Patel Sep 05 '17 at 20:44
  • And depending on what you're doing, you may want to use [startActivityForResult()](https://stackoverflow.com/questions/18243515/android-going-back-to-previous-activity-with-different-intent-value/18243541#18243541) in main – codeMagic Sep 05 '17 at 20:54
  • Voted to reopen because the linked question appears to be about passing data _up_ the activity stack, but this user's question seems more likely to regard passing data _down_ the activity stack (which would be solved by using `startActivityForResult()`, as you mentioned). – Ben P. Sep 05 '17 at 21:04
  • try using intent and bundle – Faisal Naseer Sep 05 '17 at 21:16

2 Answers2

0

You need to declare an interface, and implement the method.

Use something like this Android: TimePickerDialog - TimePickerDialog.OnTimeSetListener

I hope this help.

Cristian Cardoso
  • 665
  • 6
  • 11
-2

Try to make your variable date public static so that you can access it within another class such as MainActivity.

Bradzer
  • 146
  • 2
  • 10