I am creating an application in which I want to have Alarm like functionality. I mean on my parent view there will be a button which on click will show a view where user can take action, then when he clicks on save then the data from the child view is passed to parent view and is shown in listvi开发者_运维百科ew on parent view. The same functionality how we add new alarm in Android. I am new to android development, so please can somebody point me to some article explaining similar functionality or help me with some code?
Thanks Ashwani
When switching to the child activity, you need to use startActivityForResult
method (instead of startActivity
) of your parent activity. This way the parent will be notified when the subsequent activity is finished and returned.
Your child activity should be finished by explicitly setting the result of it (whether it is important: RESULT_OK
/ RESULT_CANCELED
), and adding the necessary data to the intent's extras (intent.putExtra(name, value);
). This will be done in the OnClickListener
of your save button.
To get the notification of the return of child activity, you have to override the onActivityResult
method of your parent activity. There you can uniquely identify the child activity by the requestCode
parameter (if you care that to be unique).
From the Intent
parameter of this method you can retrieve the extra values passed from the child activity, such as intent.getStringExtra
or intent.getSerializableExtra
.
精彩评论