I am working on an android app and using Fragments in UI layouts. In one of the fragments i needed to use a datetime picker behind a button click. I downloaded a sample datetime picker application which was implemented using dialogs in activity and i was having trouble to get it to work behind button click which was in a fragment. So what i did i just called the datetime picker activity from that button using intent which displays the datetime picker in dialog. Now after setting the date and time using picker I want that on clicking ‘OK’ button i traverse back to that fragment which called this activity and update the selected Date and Time from picker in a textview. How to achieve that?
Note that datetime picker activity is different from the activity in which fragments are created.
Fragments also contains life cycle same as Activity.
Just call finish() method from your Date picker activity.You will redirect to your last fragment,it will call onResume() of your fragment.And save your selected date in one static variable.
Another approach:
start your Date Picker activity
like below
In DatePicker activity after selecting date
write below code
by excecuting above code it finishes DatePick activity
then ovveride below method.